< prev index next >
test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn002/libforceEarlyReturn002a.cpp
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2007, 2018, Oracle and/or its affiliates. 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.
--- 1,7 ----
/*
! * Copyright (c) 2007, 2020, Oracle and/or its affiliates. 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.
*** 29,52 ****
int always_true = 1;
JNIEXPORT jint JNICALL
Java_nsk_jdwp_ThreadReference_ForceEarlyReturn_forceEarlyReturn002_forceEarlyReturn002a_nativeMethod(JNIEnv *env, jobject classObject, jobject object)
{
- int dummy_counter = 0;
// notify another thread that thread in native method
jclass klass = env->GetObjectClass(object);
jfieldID field = env->GetFieldID(klass, "threadInNative", "Z");
env->SetBooleanField(object, field, 1);
! // execute infinite loop to be sure that thread in native method
! while (always_true)
! {
! // Need some dummy code so the optimizer does not remove this loop.
! dummy_counter = dummy_counter < 1000 ? 0 : dummy_counter + 1;
! }
! // The optimizer can be surprisingly clever.
! // Use dummy_counter so it can never be optimized out.
! // This statement will always return 0.
! return dummy_counter >= 0 ? 0 : 1;
}
}
--- 29,47 ----
int always_true = 1;
JNIEXPORT jint JNICALL
Java_nsk_jdwp_ThreadReference_ForceEarlyReturn_forceEarlyReturn002_forceEarlyReturn002a_nativeMethod(JNIEnv *env, jobject classObject, jobject object)
{
// notify another thread that thread in native method
jclass klass = env->GetObjectClass(object);
jfieldID field = env->GetFieldID(klass, "threadInNative", "Z");
env->SetBooleanField(object, field, 1);
! // attempt to read char from stdin instead of infinite loop
! // because infinite loop might be eliminated by compiler optimizer.
! fgetc(stdin);
!
! // should not reach here
! return -1;
}
}
< prev index next >