Skip to content

Commit

Permalink
Merge pull request #6042 from JasonFengJ9/notthread
Browse files Browse the repository at this point in the history
Disallow thread enable/disable JVMTI_EVENT_SAMPLED_OBJECT_ALLOC
  • Loading branch information
gacholio authored Jun 11, 2019
2 parents 7598ccd + afff596 commit 22792ec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
7 changes: 5 additions & 2 deletions runtime/jvmti/jvmtiEventManagement.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ jvmtiSetEventNotificationMode(jvmtiEnv* env,
{
J9JVMTIEnv * j9env = (J9JVMTIEnv *) env;
J9JavaVM * vm = j9env->vm;
J9VMThread * currentThread;
jvmtiError rc;
J9VMThread * currentThread = NULL;
jvmtiError rc = JVMTI_ERROR_NONE;

Trc_JVMTI_jvmtiSetEventNotificationMode_Entry(env);

Expand Down Expand Up @@ -185,6 +185,9 @@ jvmtiSetEventNotificationMode(jvmtiEnv* env,
case JVMTI_EVENT_COMPILED_METHOD_UNLOAD:
case JVMTI_EVENT_DYNAMIC_CODE_GENERATED:
case JVMTI_EVENT_DATA_DUMP_REQUEST:
#if JAVA_SPEC_VERSION >= 11
case JVMTI_EVENT_SAMPLED_OBJECT_ALLOC:
#endif /* JAVA_SPEC_VERSION >= 11 */
if (event_thread != NULL) {
JVMTI_ERROR(JVMTI_ERROR_ILLEGAL_ARGUMENT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ Java_com_ibm_jvmti_tests_samplingObjectAllocation_soae001_reset(JNIEnv *jni_env,
}

jint JNICALL
Java_com_ibm_jvmti_tests_samplingObjectAllocation_soae001_enable(JNIEnv *jni_env, jclass cls)
Java_com_ibm_jvmti_tests_samplingObjectAllocation_soae001_enable(JNIEnv *jni_env, jclass cls, jthread thread)
{
jint result = JNI_OK;
jvmtiError err = JVMTI_ERROR_NONE;
JVMTI_ACCESS_FROM_AGENT(env);

/* Enable the JVMTI_EVENT_SAMPLED_OBJECT_ALLOC callback */
err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, JVMTI_EVENT_SAMPLED_OBJECT_ALLOC, NULL);
err = (*jvmti_env)->SetEventNotificationMode(jvmti_env, JVMTI_ENABLE, JVMTI_EVENT_SAMPLED_OBJECT_ALLOC, thread);
if (JVMTI_ERROR_NONE != err) {
error(env, err, "Failed to enable JVMTI_EVENT_SAMPLED_OBJECT_ALLOC event");
softError(env, err, "Failed to enable JVMTI_EVENT_SAMPLED_OBJECT_ALLOC event");
result = JNI_ERR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class soae001 {
private final static int DEFAULT_SAMPLING_RATE = 512 * 1024; /* 512 KB */

private native static void reset(); /* reset native internal counters */
private native static int enable(); /* enable event JVMTI_EVENT_SAMPLED_OBJECT_ALLOC */
private native static int enable(Thread thread); /* enable event JVMTI_EVENT_SAMPLED_OBJECT_ALLOC */
private native static int disable(); /* disable event JVMTI_EVENT_SAMPLED_OBJECT_ALLOC */
private native static int check(); /* check how many times the event callback was invoked */

Expand All @@ -34,7 +34,7 @@ public boolean testDefaultInterval() {
int jvmtiResult = 0;

reset();
jvmtiResult = enable();
jvmtiResult = enable(null);
if (0 != jvmtiResult) {
System.out.println("com.ibm.jvmti.tests.samplingObjectAllocation.soae001.enable() failed with: " + jvmtiResult);
} else {
Expand All @@ -46,16 +46,12 @@ public boolean testDefaultInterval() {
if (samplingResult < 1) {
System.out.println("com.ibm.jvmti.tests.samplingObjectAllocation.soae001.check() failed, expected 1+ but got: " + samplingResult);
} else {
jvmtiResult = disable();
jvmtiResult = enable(Thread.currentThread());
if (0 != jvmtiResult) {
System.out.println("com.ibm.jvmti.tests.samplingObjectAllocation.soae001.disable() failed with: " + jvmtiResult);
} else {
reset();
bytes = new byte[DEFAULT_SAMPLING_RATE];
System.out.println("Allocated another byte array with size " + bytes.length);
samplingResult = check();
if (0 != samplingResult) {
System.out.println("com.ibm.jvmti.tests.samplingObjectAllocation.soae001.check() failed, expected 0 but got: " + samplingResult);
System.out.println("com.ibm.jvmti.tests.samplingObjectAllocation.soae001.enable(thread) failed as expected with: " + jvmtiResult);
jvmtiResult = disable();
if (0 != jvmtiResult) {
System.out.println("com.ibm.jvmti.tests.samplingObjectAllocation.soae001.disable() failed with: " + jvmtiResult);
} else {
result = true;
}
Expand Down

0 comments on commit 22792ec

Please sign in to comment.