# HG changeset patch # User pchelko # Date 1395047424 -14400 # Node ID 1bc509cbe2a35bdd87e56edd0634c731be85687d # Parent 126ade88eb63e2edccfdb1d1efdbafafb20439a6 8035626: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_Toolkit.cpp, awt_Toolkit.h Reviewed-by: anthony, art, serb diff -r 126ade88eb63 -r 1bc509cbe2a3 jdk/src/windows/native/sun/windows/awt_Toolkit.cpp --- a/jdk/src/windows/native/sun/windows/awt_Toolkit.cpp Mon Mar 17 13:03:39 2014 +0400 +++ b/jdk/src/windows/native/sun/windows/awt_Toolkit.cpp Mon Mar 17 13:10:24 2014 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -172,35 +172,22 @@ if (awtAutoShutdownClass == NULL) { jclass awtAutoShutdownClassLocal = env->FindClass("sun/awt/AWTAutoShutdown"); - if (!JNU_IsNull(env, safe_ExceptionOccurred(env))) { - env->ExceptionDescribe(); - env->ExceptionClear(); - } DASSERT(awtAutoShutdownClassLocal != NULL); - if (awtAutoShutdownClassLocal == NULL) { - return; - } + if (!awtAutoShutdownClassLocal) throw std::bad_alloc(); awtAutoShutdownClass = (jclass)env->NewGlobalRef(awtAutoShutdownClassLocal); env->DeleteLocalRef(awtAutoShutdownClassLocal); + if (!awtAutoShutdownClass) throw std::bad_alloc(); notifyBusyMethodID = env->GetStaticMethodID(awtAutoShutdownClass, "notifyToolkitThreadBusy", "()V"); - if (!JNU_IsNull(env, safe_ExceptionOccurred(env))) { - env->ExceptionDescribe(); - env->ExceptionClear(); - } + DASSERT(notifyBusyMethodID != NULL); + if (!notifyBusyMethodID) throw std::bad_alloc(); + notifyFreeMethodID = env->GetStaticMethodID(awtAutoShutdownClass, "notifyToolkitThreadFree", "()V"); - if (!JNU_IsNull(env, safe_ExceptionOccurred(env))) { - env->ExceptionDescribe(); - env->ExceptionClear(); - } - DASSERT(notifyBusyMethodID != NULL); DASSERT(notifyFreeMethodID != NULL); - if (notifyBusyMethodID == NULL || notifyFreeMethodID == NULL) { - return; - } + if (!notifyFreeMethodID) throw std::bad_alloc(); } /* awtAutoShutdownClass == NULL*/ if (busy) { @@ -776,9 +763,11 @@ jclass systemColorClass = env->FindClass("java/awt/SystemColor"); DASSERT(systemColorClass); + if (!systemColorClass) throw std::bad_alloc(); jmethodID mid = env->GetStaticMethodID(systemColorClass, "updateSystemColors", "()V"); DASSERT(mid); + if (!mid) throw std::bad_alloc(); env->CallStaticVoidMethod(systemColorClass, mid); @@ -1038,6 +1027,8 @@ // Notify Java side - call WToolkit.displayChanged() jclass clazz = env->FindClass("sun/awt/windows/WToolkit"); + DASSERT(clazz != NULL); + if (!clazz) throw std::bad_alloc(); env->CallStaticVoidMethod(clazz, AwtToolkit::displayChangeMID); GetInstance().m_displayChanged = TRUE; @@ -2050,15 +2041,20 @@ AwtToolkit::getDefaultToolkitMID = env->GetStaticMethodID(cls,"getDefaultToolkit","()Ljava/awt/Toolkit;"); + DASSERT(AwtToolkit::getDefaultToolkitMID != NULL); + CHECK_NULL(AwtToolkit::getDefaultToolkitMID); + AwtToolkit::getFontMetricsMID = - env->GetMethodID(cls, "getFontMetrics", - "(Ljava/awt/Font;)Ljava/awt/FontMetrics;"); - AwtToolkit::insetsMID = - env->GetMethodID(env->FindClass("java/awt/Insets"), "", "(IIII)V"); - - DASSERT(AwtToolkit::getDefaultToolkitMID != NULL); + env->GetMethodID(cls, "getFontMetrics", "(Ljava/awt/Font;)Ljava/awt/FontMetrics;"); DASSERT(AwtToolkit::getFontMetricsMID != NULL); - DASSERT(AwtToolkit::insetsMID != NULL); + CHECK_NULL(AwtToolkit::getFontMetricsMID); + + jclass insetsClass = env->FindClass("java/awt/Insets"); + DASSERT(insetsClass != NULL); + CHECK_NULL(insetsClass); + AwtToolkit::insetsMID = env->GetMethodID(insetsClass, "", "(IIII)V"); + DASSERT(AwtToolkit::insetsMID != NULL); + CHECK_NULL(AwtToolkit::insetsMID); CATCH_BAD_ALLOC; } @@ -2085,10 +2081,12 @@ AwtToolkit::windowsSettingChangeMID = env->GetMethodID(cls, "windowsSettingChange", "()V"); DASSERT(AwtToolkit::windowsSettingChangeMID != 0); + CHECK_NULL(AwtToolkit::windowsSettingChangeMID); AwtToolkit::displayChangeMID = env->GetStaticMethodID(cls, "displayChanged", "()V"); DASSERT(AwtToolkit::displayChangeMID != 0); + CHECK_NULL(AwtToolkit::displayChangeMID); // Set various global IDs needed by JAWT code. Note: these // variables cannot be set by JAWT code directly due to @@ -2099,24 +2097,37 @@ // negligible penalty. jclass sDataClassLocal = env->FindClass("sun/java2d/SurfaceData"); DASSERT(sDataClassLocal != 0); + CHECK_NULL(sDataClassLocal); + jclass vImgClassLocal = env->FindClass("sun/awt/image/SunVolatileImage"); DASSERT(vImgClassLocal != 0); + CHECK_NULL(vImgClassLocal); + jclass vSMgrClassLocal = env->FindClass("sun/awt/image/VolatileSurfaceManager"); DASSERT(vSMgrClassLocal != 0); + CHECK_NULL(vSMgrClassLocal); + jclass componentClassLocal = env->FindClass("java/awt/Component"); DASSERT(componentClassLocal != 0); + CHECK_NULL(componentClassLocal); + jawtSMgrID = env->GetFieldID(vImgClassLocal, "volSurfaceManager", "Lsun/awt/image/VolatileSurfaceManager;"); DASSERT(jawtSMgrID != 0); + CHECK_NULL(jawtSMgrID); + jawtSDataID = env->GetFieldID(vSMgrClassLocal, "sdCurrent", "Lsun/java2d/SurfaceData;"); DASSERT(jawtSDataID != 0); + CHECK_NULL(jawtSDataID); + jawtPDataID = env->GetFieldID(sDataClassLocal, "pData", "J"); DASSERT(jawtPDataID != 0); - + CHECK_NULL(jawtPDataID); // Save these classes in global references for later use jawtVImgClass = (jclass)env->NewGlobalRef(vImgClassLocal); + CHECK_NULL(jawtVImgClass); jawtComponentClass = (jclass)env->NewGlobalRef(componentClassLocal); CATCH_BAD_ALLOC; @@ -2377,7 +2388,11 @@ TRY; if (AwtToolkit::GetScreenInsets(screen, &rect)) { - insets = env->NewObject(env->FindClass("java/awt/Insets"), + jclass insetsClass = env->FindClass("java/awt/Insets"); + DASSERT(insetsClass != NULL); + CHECK_NULL_RETURN(insetsClass, NULL); + + insets = env->NewObject(insetsClass, AwtToolkit::insetsMID, rect.top, rect.left, diff -r 126ade88eb63 -r 1bc509cbe2a3 jdk/src/windows/native/sun/windows/awt_Toolkit.h --- a/jdk/src/windows/native/sun/windows/awt_Toolkit.h Mon Mar 17 13:03:39 2014 +0400 +++ b/jdk/src/windows/native/sun/windows/awt_Toolkit.h Mon Mar 17 13:10:24 2014 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -80,7 +80,7 @@ int result = m_env->PushLocalFrame(size); if (result < 0) { DASSERT(FALSE); - JNU_ThrowOutOfMemoryError(m_env, "Can't allocate localRefs"); + throw std::bad_alloc(); } } INLINE ~JNILocalFrame() { m_env->PopLocalFrame(NULL); }