# HG changeset patch # User rkennke # Date 1573754352 -3600 # Thu Nov 14 18:59:12 2019 +0100 # Node ID 278fa2321f4992b668f8d9d6c5b3508d6f44d2b6 # Parent 4095ba341695e5b553be4c1808d1cea606ac82bd [mq]: JDK-8234096-test.patch diff --git a/src/share/vm/gc_implementation/shenandoah/shenandoahHeap.inline.hpp b/src/share/vm/gc_implementation/shenandoah/shenandoahHeap.inline.hpp --- a/src/share/vm/gc_implementation/shenandoah/shenandoahHeap.inline.hpp +++ b/src/share/vm/gc_implementation/shenandoah/shenandoahHeap.inline.hpp @@ -278,7 +278,7 @@ } inline bool ShenandoahHeap::requires_marking(const void* entry) const { - return !_marking_context->is_marked(oop(entry)); + return !ShenandoahSATBFilter || !_marking_context->is_marked(oop(entry)); } template diff --git a/src/share/vm/gc_implementation/shenandoah/shenandoah_globals.hpp b/src/share/vm/gc_implementation/shenandoah/shenandoah_globals.hpp --- a/src/share/vm/gc_implementation/shenandoah/shenandoah_globals.hpp +++ b/src/share/vm/gc_implementation/shenandoah/shenandoah_globals.hpp @@ -372,6 +372,9 @@ product(bool, ShenandoahLogWarning, false, \ "Turns on logging in Shenandoah at warning level. ") \ \ + develop(bool, ShenandoahSATBFilter, true, \ + "Turns off SATB filtering when false. ") \ + \ SHENANDOAH_FLAGS(DECLARE_DEVELOPER_FLAG, \ DECLARE_PD_DEVELOPER_FLAG, \ diff --git a/test/TEST.groups b/test/TEST.groups --- a/test/TEST.groups +++ b/test/TEST.groups @@ -163,6 +163,9 @@ :hotspot_tier2_gc_shenandoah \ :hotspot_tier3_gc_shenandoah +hotspot_jvmti_gc_shenandoah = \ + gc/shenandoah/jvmti/TestGetLoadedClasses.sh \ + hotspot_runtime = \ sanity/ExecuteInternalVMTests.java diff --git a/test/gc/shenandoah/jvmti/TestGetLoadedClasses.java b/test/gc/shenandoah/jvmti/TestGetLoadedClasses.java new file mode 100644 --- /dev/null +++ b/test/gc/shenandoah/jvmti/TestGetLoadedClasses.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2019, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +public class TestGetLoadedClasses { + + private static final int NUM_ITER = 10000; + + static { + try { + System.loadLibrary("TestGetLoadedClasses"); + } catch (UnsatisfiedLinkError ule) { + System.err.println("Could not load TestGetLoadedClasses library"); + System.err.println("java.library.path: " + + System.getProperty("java.library.path")); + throw ule; + } + } + + native static int getLoadedClasses(); + + public static void main(String args[]) { + new TestGetLoadedClasses().run(); + } + + public void run() { + for (int i = 0; i < NUM_ITER; i++) { + int count = getLoadedClasses(); + } + } +} diff --git a/test/gc/shenandoah/jvmti/TestGetLoadedClasses.sh b/test/gc/shenandoah/jvmti/TestGetLoadedClasses.sh new file mode 100644 --- /dev/null +++ b/test/gc/shenandoah/jvmti/TestGetLoadedClasses.sh @@ -0,0 +1,102 @@ +#!/bin/sh + +# +# Copyright (c) 2019, Red Hat, Inc. All rights reserved. +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +## +## @test +## @summary test JVMTI GetLoadedClasses in Shenandoah +## @run shell/timeout=480 TestGetLoadedClasses.sh +## + +if [ "${TESTSRC}" = "" ] +then + TESTSRC=${PWD} + echo "TESTSRC not set. Using "${TESTSRC}" as default" +fi +echo "TESTSRC=${TESTSRC}" +## Adding common setup Variables for running shell tests. +. ${TESTSRC}/../../../test_env.sh + +# set platform-dependent variables +if [ "$VM_OS" = "linux" ]; then + echo "Testing on linux" + gcc_cmd=`which gcc` + if [ "x$gcc_cmd" = "x" ]; then + echo "WARNING: gcc not found. Cannot execute test." 2>&1 + exit 0; + fi +else + echo "Test passed; only valid for linux: $VM_OS" + exit 0; +fi + +# Unfortunately, configurations cross-compiled to 32 bits would +# fail with bitness mismatch, when compiled with platform gcc. +# This would be fixed with /native support in JDK-8072842. +if [ "$VM_BITS" = "32" ]; then + echo "Test passed; only reliable on 64-bit" + exit 0; +fi + +THIS_DIR=. + +cp ${TESTSRC}${FS}*.java ${THIS_DIR} +${TESTJAVA}${FS}bin${FS}javac TestGetLoadedClasses.java + +$gcc_cmd -O1 -DLINUX -fPIC -shared \ + -o ${THIS_DIR}${FS}libTestGetLoadedClasses.so \ + -I${TESTJAVA}${FS}include \ + -I${TESTJAVA}${FS}include${FS}linux \ + ${TESTSRC}${FS}libTestGetLoadedClasses.c + +# run the java test in the background +cmd="${TESTJAVA}${FS}bin${FS}java -agentpath:./libTestGetLoadedClasses.so -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive \ + -XX:ShenandoahSATBBufferSize=1 -XX:-ShenandoahSATBFilter -Djava.library.path=${THIS_DIR}${FS} TestGetLoadedClasses" + +echo "$cmd" +eval $cmd + +if [ $? -ne 0 ] +then + echo "Test Failed" + exit 1 +fi + +if [ "$VM_BITS" = "64" ]; then + cmd="${TESTJAVA}${FS}bin${FS}java -agentpath:./libTestGetLoadedClasses.so -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive \ + -XX:ShenandoahSATBBufferSize=1 -XX:-ShenandoahSATBFilter -XX:-UseCompressedOops -Djava.library.path=${THIS_DIR}${FS} TestGetLoadedClasses" + + echo "$cmd" + eval $cmd + + if [ $? -ne 0 ] + then + echo "Test Failed" + exit 1 + fi +else + echo "Test passed; only valid for 64 bits" + exit 0; +fi diff --git a/test/gc/shenandoah/jvmti/libTestGetLoadedClasses.c b/test/gc/shenandoah/jvmti/libTestGetLoadedClasses.c new file mode 100644 --- /dev/null +++ b/test/gc/shenandoah/jvmti/libTestGetLoadedClasses.c @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2019, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#include +#include +#include "jvmti.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef JNI_ENV_ARG + +#ifdef __cplusplus +#define JNI_ENV_ARG(x, y) y +#define JNI_ENV_PTR(x) x +#else +#define JNI_ENV_ARG(x,y) x, y +#define JNI_ENV_PTR(x) (*x) +#endif + +#endif + +static const char *EXC_CNAME = "java/lang/Exception"; + +static jvmtiEnv *jvmti = NULL; + +static jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved); + +JNIEXPORT +jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} + +JNIEXPORT +jint JNICALL Agent_OnAttach(JavaVM *jvm, char *options, void *reserved) { + return Agent_Initialize(jvm, options, reserved); +} + +JNIEXPORT +jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) { + return JNI_VERSION_1_8; +} + +static +jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { + jvmtiCapabilities capabilities; + jint res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), + JVMTI_VERSION); + if (res != JNI_OK || jvmti == NULL) { + printf(" Error: wrong result of a valid call to GetEnv!\n"); + return JNI_ERR; + } + + (void)memset(&capabilities, 0, sizeof(capabilities)); + capabilities.can_tag_objects = 1; + capabilities.can_generate_garbage_collection_events = 1; + (*jvmti)->AddCapabilities(jvmti, &capabilities); + + return JNI_OK; +} + +static +void throw_exc(JNIEnv *env, char *msg) { + jclass exc_class = JNI_ENV_PTR(env)->FindClass(JNI_ENV_ARG(env, EXC_CNAME)); + jint rt = JNI_OK; + + if (exc_class == NULL) { + printf("throw_exc: Error in FindClass(env, %s)\n", EXC_CNAME); + return; + } + rt = JNI_ENV_PTR(env)->ThrowNew(JNI_ENV_ARG(env, exc_class), msg); + if (rt == JNI_ERR) { + printf("throw_exc: Error in JNI ThrowNew(env, %s)\n", msg); + } +} + +JNIEXPORT jint JNICALL +Java_TestGetLoadedClasses_getLoadedClasses(JNIEnv *env, jclass cls) { + jint totalCount = 0; + jclass* classes; + if (jvmti == NULL) { + throw_exc(env, "JVMTI client was not properly loaded!\n"); + return 0; + } + + (*jvmti)->GetLoadedClasses(jvmti, &totalCount, &classes); + (*jvmti)->Deallocate(jvmti, (unsigned char*)classes); + return totalCount; +} + +#ifdef __cplusplus +} +#endif