Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atomic-free JNI work #1923

Merged
merged 1 commit into from
May 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 58 additions & 56 deletions runtime/jvmti/jvmtiRawMonitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,45 +94,47 @@ jvmtiRawMonitorEnter(jvmtiEnv* env,

rc = getCurrentVMThread(vm, &currentThread);
if (rc == JVMTI_ERROR_NONE) {
/* JDK blocks here if the current thread is suspended - don't do VM access stuff if the current thread has exclusive */

if (currentThread->publicFlags & J9_PUBLIC_FLAGS_HALT_THREAD_ANY) {
if (currentThread->omrVMThread->exclusiveCount == 0) {
/* Acquire VM access if the current thread does not already have it */
#if defined(J9VM_INTERP_ATOMIC_FREE_JNI)
if (currentThread->inNative)
if (currentThread->inNative)
#else /* J9VM_INTERP_ATOMIC_FREE_JNI */
if (0 == (currentThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS))
#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */
{
/* JDK blocks here if the current thread is suspended - don't do VM access stuff if the current thread has exclusive */

if (currentThread->publicFlags & J9_PUBLIC_FLAGS_HALT_THREAD_ANY) {
if (currentThread->omrVMThread->exclusiveCount == 0) {
/* Acquire VM access if the current thread does not already have it */
if (0 == (currentThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS)) {
{
block:
vm->internalVMFunctions->internalEnterVMFromJNI(currentThread);
vm->internalVMFunctions->internalExitVMToJNI(currentThread);
}
vm->internalVMFunctions->internalEnterVMFromJNI(currentThread);
vm->internalVMFunctions->internalExitVMToJNI(currentThread);
}
}
}

if (0 == omrthread_monitor_enter((omrthread_monitor_t) monitor)) {
/* CMVC 157789 : If the current thread is supposed to be blocked right now.
* release the monitor and block to simulate blocking before acquiring the
* monitor.
*/
if (currentThread->publicFlags & J9_PUBLIC_FLAGS_HALT_THREAD_ANY) {
if (currentThread->omrVMThread->exclusiveCount == 0) {
#if defined(J9VM_INTERP_ATOMIC_FREE_JNI)
if (currentThread->inNative)
if (currentThread->inNative)
#else /* J9VM_INTERP_ATOMIC_FREE_JNI */
if (0 == (currentThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS))
#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */
{
/* CMVC 157789 : If the current thread is supposed to be blocked right now.
* release the monitor and block to simulate blocking before acquiring the
* monitor.
*/
if (currentThread->publicFlags & J9_PUBLIC_FLAGS_HALT_THREAD_ANY) {
if (currentThread->omrVMThread->exclusiveCount == 0) {
if (0 == (currentThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS)) {
omrthread_monitor_exit((omrthread_monitor_t) monitor);
goto block;
}
{
omrthread_monitor_exit((omrthread_monitor_t) monitor);
goto block;
}
}
}
} else {
#if defined(J9VM_INTERP_ATOMIC_FREE_JNI)
if (currentThread->inNative)
#else /* J9VM_INTERP_ATOMIC_FREE_JNI */
if (0 == (currentThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS))
#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */
{
vm->internalVMFunctions->internalEnterVMFromJNI(currentThread);
Expand Down Expand Up @@ -165,21 +167,21 @@ jvmtiRawMonitorExit(jvmtiEnv* env,
rc = JVMTI_ERROR_NOT_MONITOR_OWNER;
}

/* JDK blocks here if the current thread is suspended - don't do VM access stuff if the current thread has exclusive */

if (currentThread->publicFlags & J9_PUBLIC_FLAGS_HALT_THREAD_ANY) {
if (currentThread->omrVMThread->exclusiveCount == 0) {
/* Acquire VM access if the current thread does not already have it */
#if defined(J9VM_INTERP_ATOMIC_FREE_JNI)
if (currentThread->inNative)
if (currentThread->inNative)
#else /* J9VM_INTERP_ATOMIC_FREE_JNI */
if (0 == (currentThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS))
#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */
{
/* JDK blocks here if the current thread is suspended - don't do VM access stuff if the current thread has exclusive */

if (currentThread->publicFlags & J9_PUBLIC_FLAGS_HALT_THREAD_ANY) {
if (currentThread->omrVMThread->exclusiveCount == 0) {
/* Acquire VM access if the current thread does not already have it */
if (0 == (currentThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS)) {
vm->internalVMFunctions->internalEnterVMFromJNI(currentThread);
vm->internalVMFunctions->internalExitVMToJNI(currentThread);
}
/* There is still a timing hole here, since the thread may be suspended at this point */
{
vm->internalVMFunctions->internalEnterVMFromJNI(currentThread);
vm->internalVMFunctions->internalExitVMToJNI(currentThread);
}
/* There is still a timing hole here, since the thread may be suspended at this point */
}
}
}
Expand Down Expand Up @@ -224,31 +226,31 @@ jvmtiRawMonitorWait(jvmtiEnv* env,
break;
}

#if defined(J9VM_INTERP_ATOMIC_FREE_JNI)
if (currentThread->inNative)
#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */
{
/* JDK blocks here if the current thread is suspended - don't do VM access stuff if the current thread has exclusive */
/* JDK blocks here if the current thread is suspended - don't do VM access stuff if the current thread has exclusive */

if (currentThread->publicFlags & J9_PUBLIC_FLAGS_HALT_THREAD_ANY) {
if (currentThread->omrVMThread->exclusiveCount == 0) {
UDATA count = 0;
if (currentThread->publicFlags & J9_PUBLIC_FLAGS_HALT_THREAD_ANY) {
if (currentThread->omrVMThread->exclusiveCount == 0) {
UDATA count = 0;

/* TODO: revisit and remove all together after we switch to harmony jdwp */
while (omrthread_monitor_exit((omrthread_monitor_t) monitor) == 0) {
++count;
}
/* TODO: revisit and remove all together after we switch to harmony jdwp */
while (omrthread_monitor_exit((omrthread_monitor_t) monitor) == 0) {
++count;
}

/* Acquire VM access if the current thread does not already have it */
if (0 == (currentThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS)) {
vm->internalVMFunctions->internalEnterVMFromJNI(currentThread);
vm->internalVMFunctions->internalExitVMToJNI(currentThread);
}
/* Acquire VM access if the current thread does not already have it */
#if defined(J9VM_INTERP_ATOMIC_FREE_JNI)
if (currentThread->inNative)
#else /* J9VM_INTERP_ATOMIC_FREE_JNI */
if (0 == (currentThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS))
#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */
{
vm->internalVMFunctions->internalEnterVMFromJNI(currentThread);
vm->internalVMFunctions->internalExitVMToJNI(currentThread);
}

/* There is still a timing hole here, since the thread may be suspended at this point */
while (count-- != 0) {
omrthread_monitor_enter((omrthread_monitor_t) monitor);
}
/* There is still a timing hole here, since the thread may be suspended at this point */
while (count-- != 0) {
omrthread_monitor_enter((omrthread_monitor_t) monitor);
}
}
}
Expand Down