--- old/src/java.desktop/unix/native/libawt_xawt/awt/awt_util.c 2016-07-06 15:21:51.814740423 +0530 +++ new/src/java.desktop/unix/native/libawt_xawt/awt/awt_util.c 2016-07-06 15:21:51.590740423 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2016, 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 @@ -65,35 +65,31 @@ awtJNI_ThreadYield(JNIEnv *env) { static jclass threadClass = NULL; - static jmethodID yieldMethodID = NULL; + static volatile jmethodID yieldMethodID = NULL; - /* Initialize our java identifiers once. Checking before locking - * is a huge performance win. + /* Double Check Locking is used with volatile yieldMethodID identifier + * to initialize java identifiers only once & multi-thread safe. */ - if (threadClass == NULL) { - // should enter a monitor here... - Boolean err = FALSE; - if (threadClass == NULL) { + + if (yieldMethodID == NULL) { + AWT_LOCK(); + if (yieldMethodID == NULL) { jclass tc = (*env)->FindClass(env, "java/lang/Thread"); CHECK_NULL_RETURN(tc, JNI_FALSE); threadClass = (*env)->NewGlobalRef(env, tc); + (*env)->DeleteLocalRef(env, tc); if (threadClass != NULL) { - yieldMethodID = (*env)->GetStaticMethodID(env, - threadClass, - "yield", - "()V" - ); + yieldMethodID = (*env)->GetStaticMethodID(env, threadClass, + "yield", "()V"); } } + AWT_UNLOCK(); if (yieldMethodID == NULL) { threadClass = NULL; - err = TRUE; - } - if (err) { return JNI_FALSE; } - } /* threadClass == NULL*/ + } (*env)->CallStaticVoidMethod(env, threadClass, yieldMethodID); DASSERT(!((*env)->ExceptionOccurred(env)));