< prev index next >

src/java.desktop/unix/native/libawt_xawt/awt/awt_util.c

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1995, 2014, 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. Oracle designates this --- 1,7 ---- /* ! * 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 63,101 **** jboolean awtJNI_ThreadYield(JNIEnv *env) { static jclass threadClass = NULL; ! static jmethodID yieldMethodID = NULL; ! /* Initialize our java identifiers once. Checking before locking ! * is a huge performance win. */ ! if (threadClass == NULL) { ! // should enter a monitor here... ! Boolean err = FALSE; ! if (threadClass == 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" ! ); } } if (yieldMethodID == NULL) { threadClass = NULL; - err = TRUE; - } - if (err) { return JNI_FALSE; } ! } /* threadClass == NULL*/ (*env)->CallStaticVoidMethod(env, threadClass, yieldMethodID); DASSERT(!((*env)->ExceptionOccurred(env))); if ((*env)->ExceptionCheck(env)) { return JNI_FALSE; --- 63,97 ---- jboolean awtJNI_ThreadYield(JNIEnv *env) { static jclass threadClass = NULL; ! static volatile jmethodID yieldMethodID = NULL; ! /* Double Check Locking is used with volatile yieldMethodID identifier ! * to initialize java identifiers only once & multi-thread safe. */ ! ! 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"); } } + AWT_UNLOCK(); if (yieldMethodID == NULL) { threadClass = NULL; return JNI_FALSE; } ! } (*env)->CallStaticVoidMethod(env, threadClass, yieldMethodID); DASSERT(!((*env)->ExceptionOccurred(env))); if ((*env)->ExceptionCheck(env)) { return JNI_FALSE;
< prev index next >