# HG changeset patch # User redestad # Date 1570523062 -7200 # Node ID 55a8d95c7787755aade3f713226d7c86d6424214 # Parent 227ddf1ff93d3aac142aa418137d549f3a353568 8231355: Remove unused utility methods in libjava Reviewed-by: dholmes, jrose, alanb diff -r 227ddf1ff93d -r 55a8d95c7787 src/hotspot/share/classfile/javaClasses.cpp --- a/src/hotspot/share/classfile/javaClasses.cpp Tue Oct 08 09:33:57 2019 +0200 +++ b/src/hotspot/share/classfile/javaClasses.cpp Tue Oct 08 10:24:22 2019 +0200 @@ -377,7 +377,7 @@ if (_to_java_string_fn == NULL) { void *lib_handle = os::native_java_library(); - _to_java_string_fn = CAST_TO_FN_PTR(to_java_string_fn_t, os::dll_lookup(lib_handle, "NewStringPlatform")); + _to_java_string_fn = CAST_TO_FN_PTR(to_java_string_fn_t, os::dll_lookup(lib_handle, "JNU_NewStringPlatform")); if (_to_java_string_fn == NULL) { fatal("NewStringPlatform missing"); } diff -r 227ddf1ff93d -r 55a8d95c7787 src/java.base/share/native/libjava/VM.c --- a/src/java.base/share/native/libjava/VM.c Tue Oct 08 09:33:57 2019 +0200 +++ b/src/java.base/share/native/libjava/VM.c Tue Oct 08 10:24:22 2019 +0200 @@ -42,11 +42,6 @@ JNIEXPORT void JNICALL Java_jdk_internal_misc_VM_initialize(JNIEnv *env, jclass cls) { - if (!JDK_InitJvmHandle()) { - JNU_ThrowInternalError(env, "Handle for JVM not found for symbol lookup"); - return; - } - // Registers implementations of native methods described in methods[] // above. // In particular, registers JVM_GetNanoTimeAdjustment as the implementation diff -r 227ddf1ff93d -r 55a8d95c7787 src/java.base/share/native/libjava/jdk_util.h --- a/src/java.base/share/native/libjava/jdk_util.h Tue Oct 08 09:33:57 2019 +0200 +++ b/src/java.base/share/native/libjava/jdk_util.h Tue Oct 08 10:24:22 2019 +0200 @@ -45,20 +45,6 @@ JNIEXPORT void JDK_GetVersionInfo0(jdk_version_info* info, size_t info_size); - -/*------------------------------------------------------- - * Internal interface for JDK to use - *------------------------------------------------------- - */ - -/* Init JVM handle for symbol lookup; - * Return 0 if JVM handle not found. - */ -int JDK_InitJvmHandle(); - -/* Find the named JVM entry; returns NULL if not found. */ -void* JDK_FindJvmEntry(const char* name); - #ifdef __cplusplus } /* extern "C" */ #endif /* __cplusplus */ diff -r 227ddf1ff93d -r 55a8d95c7787 src/java.base/share/native/libjava/jni_util.c --- a/src/java.base/share/native/libjava/jni_util.c Tue Oct 08 09:33:57 2019 +0200 +++ b/src/java.base/share/native/libjava/jni_util.c Tue Oct 08 10:24:22 2019 +0200 @@ -77,77 +77,23 @@ } JNIEXPORT void JNICALL -JNU_ThrowIllegalAccessError(JNIEnv *env, const char *msg) -{ - JNU_ThrowByName(env, "java/lang/IllegalAccessError", msg); -} - -JNIEXPORT void JNICALL -JNU_ThrowIllegalAccessException(JNIEnv *env, const char *msg) -{ - JNU_ThrowByName(env, "java/lang/IllegalAccessException", msg); -} - -JNIEXPORT void JNICALL JNU_ThrowInternalError(JNIEnv *env, const char *msg) { JNU_ThrowByName(env, "java/lang/InternalError", msg); } JNIEXPORT void JNICALL -JNU_ThrowNoSuchFieldException(JNIEnv *env, const char *msg) -{ - JNU_ThrowByName(env, "java/lang/NoSuchFieldException", msg); -} - -JNIEXPORT void JNICALL -JNU_ThrowNoSuchMethodException(JNIEnv *env, const char *msg) -{ - JNU_ThrowByName(env, "java/lang/NoSuchMethodException", msg); -} - -JNIEXPORT void JNICALL JNU_ThrowClassNotFoundException(JNIEnv *env, const char *msg) { JNU_ThrowByName(env, "java/lang/ClassNotFoundException", msg); } JNIEXPORT void JNICALL -JNU_ThrowNumberFormatException(JNIEnv *env, const char *msg) -{ - JNU_ThrowByName(env, "java/lang/NumberFormatException", msg); -} - -JNIEXPORT void JNICALL JNU_ThrowIOException(JNIEnv *env, const char *msg) { JNU_ThrowByName(env, "java/io/IOException", msg); } -JNIEXPORT void JNICALL -JNU_ThrowNoSuchFieldError(JNIEnv *env, const char *msg) -{ - JNU_ThrowByName(env, "java/lang/NoSuchFieldError", msg); -} - -JNIEXPORT void JNICALL -JNU_ThrowNoSuchMethodError(JNIEnv *env, const char *msg) -{ - JNU_ThrowByName(env, "java/lang/NoSuchMethodError", msg); -} - -JNIEXPORT void JNICALL -JNU_ThrowStringIndexOutOfBoundsException(JNIEnv *env, const char *msg) -{ - JNU_ThrowByName(env, "java/lang/StringIndexOutOfBoundsException", msg); -} - -JNIEXPORT void JNICALL -JNU_ThrowInstantiationException(JNIEnv *env, const char *msg) -{ - JNU_ThrowByName(env, "java/lang/InstantiationException", msg); -} - /* * Throw an exception by name, using the string returned by * getLastErrorString for the detail string. If the last-error @@ -845,12 +791,6 @@ CHECK_NULL(String_value_ID); } -JNIEXPORT jstring -NewStringPlatform(JNIEnv *env, const char *str) -{ - return JNU_NewStringPlatform(env, str); -} - JNIEXPORT jstring JNICALL JNU_NewStringPlatform(JNIEnv *env, const char *str) { @@ -1024,54 +964,6 @@ return cls; } -JNIEXPORT jclass JNICALL -JNU_ClassClass(JNIEnv *env) -{ - static jclass cls = 0; - if (cls == 0) { - jclass c; - if ((*env)->EnsureLocalCapacity(env, 1) < 0) - return 0; - c = (*env)->FindClass(env, "java/lang/Class"); - CHECK_NULL_RETURN(c, NULL); - cls = (*env)->NewGlobalRef(env, c); - (*env)->DeleteLocalRef(env, c); - } - return cls; -} - -JNIEXPORT jclass JNICALL -JNU_ClassObject(JNIEnv *env) -{ - static jclass cls = 0; - if (cls == 0) { - jclass c; - if ((*env)->EnsureLocalCapacity(env, 1) < 0) - return 0; - c = (*env)->FindClass(env, "java/lang/Object"); - CHECK_NULL_RETURN(c, NULL); - cls = (*env)->NewGlobalRef(env, c); - (*env)->DeleteLocalRef(env, c); - } - return cls; -} - -JNIEXPORT jclass JNICALL -JNU_ClassThrowable(JNIEnv *env) -{ - static jclass cls = 0; - if (cls == 0) { - jclass c; - if ((*env)->EnsureLocalCapacity(env, 1) < 0) - return 0; - c = (*env)->FindClass(env, "java/lang/Throwable"); - CHECK_NULL_RETURN(c, NULL); - cls = (*env)->NewGlobalRef(env, c); - (*env)->DeleteLocalRef(env, c); - } - return cls; -} - JNIEXPORT jint JNICALL JNU_CopyObjectArray(JNIEnv *env, jobjectArray dst, jobjectArray src, jint count) @@ -1110,125 +1002,10 @@ return JNI_ERR; } -JNIEXPORT jboolean JNICALL -JNU_Equals(JNIEnv *env, jobject object1, jobject object2) -{ - static jmethodID mid = NULL; - if (mid == NULL) { - jclass objClazz = JNU_ClassObject(env); - CHECK_NULL_RETURN(objClazz, JNI_FALSE); - mid = (*env)->GetMethodID(env, objClazz, "equals", - "(Ljava/lang/Object;)Z"); - CHECK_NULL_RETURN(mid, JNI_FALSE); - } - return (*env)->CallBooleanMethod(env, object1, mid, object2); -} - - -/************************************************************************ - * Thread calls - */ - -static jmethodID Object_waitMID; -static jmethodID Object_notifyMID; -static jmethodID Object_notifyAllMID; - -JNIEXPORT void JNICALL -JNU_MonitorWait(JNIEnv *env, jobject object, jlong timeout) -{ - if (object == NULL) { - JNU_ThrowNullPointerException(env, "JNU_MonitorWait argument"); - return; - } - if (Object_waitMID == NULL) { - jclass cls = JNU_ClassObject(env); - if (cls == NULL) { - return; - } - Object_waitMID = (*env)->GetMethodID(env, cls, "wait", "(J)V"); - if (Object_waitMID == NULL) { - return; - } - } - (*env)->CallVoidMethod(env, object, Object_waitMID, timeout); -} - -JNIEXPORT void JNICALL -JNU_Notify(JNIEnv *env, jobject object) -{ - if (object == NULL) { - JNU_ThrowNullPointerException(env, "JNU_Notify argument"); - return; - } - if (Object_notifyMID == NULL) { - jclass cls = JNU_ClassObject(env); - if (cls == NULL) { - return; - } - Object_notifyMID = (*env)->GetMethodID(env, cls, "notify", "()V"); - if (Object_notifyMID == NULL) { - return; - } - } - (*env)->CallVoidMethod(env, object, Object_notifyMID); -} - -JNIEXPORT void JNICALL -JNU_NotifyAll(JNIEnv *env, jobject object) -{ - if (object == NULL) { - JNU_ThrowNullPointerException(env, "JNU_NotifyAll argument"); - return; - } - if (Object_notifyAllMID == NULL) { - jclass cls = JNU_ClassObject(env); - if (cls == NULL) { - return; - } - Object_notifyAllMID = (*env)->GetMethodID(env, cls,"notifyAll", "()V"); - if (Object_notifyAllMID == NULL) { - return; - } - } - (*env)->CallVoidMethod(env, object, Object_notifyAllMID); -} - - /************************************************************************ * Debugging utilities */ -JNIEXPORT void JNICALL -JNU_PrintString(JNIEnv *env, char *hdr, jstring string) -{ - if (string == NULL) { - fprintf(stderr, "%s: is NULL\n", hdr); - } else { - const char *stringPtr = JNU_GetStringPlatformChars(env, string, 0); - if (stringPtr == 0) - return; - fprintf(stderr, "%s: %s\n", hdr, stringPtr); - JNU_ReleaseStringPlatformChars(env, string, stringPtr); - } -} - -JNIEXPORT void JNICALL -JNU_PrintClass(JNIEnv *env, char* hdr, jobject object) -{ - if (object == NULL) { - fprintf(stderr, "%s: object is NULL\n", hdr); - return; - } else { - jclass cls = (*env)->GetObjectClass(env, object); - jstring clsName = JNU_ToString(env, cls); - if (clsName == NULL) { - JNU_PrintString(env, hdr, clsName); - } - (*env)->DeleteLocalRef(env, cls); - (*env)->DeleteLocalRef(env, clsName); - } -} - JNIEXPORT jstring JNICALL JNU_ToString(JNIEnv *env, jobject object) { @@ -1437,70 +1214,3 @@ } return result; } - -JNIEXPORT void JNICALL -JNU_SetStaticFieldByName(JNIEnv *env, - jboolean *hasException, - const char *classname, - const char *name, - const char *signature, - ...) -{ - jclass cls; - jfieldID fid; - va_list args; - - if ((*env)->EnsureLocalCapacity(env, 3) < 0) - goto done2; - - cls = (*env)->FindClass(env, classname); - if (cls == 0) - goto done2; - - fid = (*env)->GetStaticFieldID(env, cls, name, signature); - if (fid == 0) - goto done1; - - va_start(args, signature); - switch (*signature) { - case '[': - case 'L': - (*env)->SetStaticObjectField(env, cls, fid, va_arg(args, jobject)); - break; - case 'Z': - (*env)->SetStaticBooleanField(env, cls, fid, (jboolean)va_arg(args, int)); - break; - case 'B': - (*env)->SetStaticByteField(env, cls, fid, (jbyte)va_arg(args, int)); - break; - case 'C': - (*env)->SetStaticCharField(env, cls, fid, (jchar)va_arg(args, int)); - break; - case 'S': - (*env)->SetStaticShortField(env, cls, fid, (jshort)va_arg(args, int)); - break; - case 'I': - (*env)->SetStaticIntField(env, cls, fid, va_arg(args, jint)); - break; - case 'J': - (*env)->SetStaticLongField(env, cls, fid, va_arg(args, jlong)); - break; - case 'F': - (*env)->SetStaticFloatField(env, cls, fid, (jfloat)va_arg(args, jdouble)); - break; - case 'D': - (*env)->SetStaticDoubleField(env, cls, fid, va_arg(args, jdouble)); - break; - - default: - (*env)->FatalError(env, "JNU_SetStaticFieldByName: illegal signature"); - } - va_end(args); - - done1: - (*env)->DeleteLocalRef(env, cls); - done2: - if (hasException) { - *hasException = (*env)->ExceptionCheck(env); - } -} diff -r 227ddf1ff93d -r 55a8d95c7787 src/java.base/share/native/libjava/jni_util.h --- a/src/java.base/share/native/libjava/jni_util.h Tue Oct 08 09:33:57 2019 +0200 +++ b/src/java.base/share/native/libjava/jni_util.h Tue Oct 08 10:24:22 2019 +0200 @@ -62,41 +62,14 @@ JNU_ThrowIllegalArgumentException(JNIEnv *env, const char *msg); JNIEXPORT void JNICALL -JNU_ThrowIllegalAccessError(JNIEnv *env, const char *msg); - -JNIEXPORT void JNICALL -JNU_ThrowIllegalAccessException(JNIEnv *env, const char *msg); - -JNIEXPORT void JNICALL JNU_ThrowInternalError(JNIEnv *env, const char *msg); JNIEXPORT void JNICALL JNU_ThrowIOException(JNIEnv *env, const char *msg); JNIEXPORT void JNICALL -JNU_ThrowNoSuchFieldException(JNIEnv *env, const char *msg); - -JNIEXPORT void JNICALL -JNU_ThrowNoSuchMethodException(JNIEnv *env, const char *msg); - -JNIEXPORT void JNICALL JNU_ThrowClassNotFoundException(JNIEnv *env, const char *msg); -JNIEXPORT void JNICALL -JNU_ThrowNumberFormatException(JNIEnv *env, const char *msg); - -JNIEXPORT void JNICALL -JNU_ThrowNoSuchFieldError(JNIEnv *env, const char *msg); - -JNIEXPORT void JNICALL -JNU_ThrowNoSuchMethodError(JNIEnv *env, const char *msg); - -JNIEXPORT void JNICALL -JNU_ThrowStringIndexOutOfBoundsException(JNIEnv *env, const char *msg); - -JNIEXPORT void JNICALL -JNU_ThrowInstantiationException(JNIEnv *env, const char *msg); - /* Throw an exception by name, using the string returned by * getLastErrorString for the detail string. If the last-error * string is NULL, use the given default detail string. @@ -120,9 +93,6 @@ JNU_ThrowIOExceptionWithLastError(JNIEnv *env, const char *defaultDetail); /* Convert between Java strings and i18n C strings */ -JNIEXPORT jstring -NewStringPlatform(JNIEnv *env, const char *str); - JNIEXPORT const char * GetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy); @@ -139,15 +109,6 @@ JNIEXPORT jclass JNICALL JNU_ClassString(JNIEnv *env); -JNIEXPORT jclass JNICALL -JNU_ClassClass(JNIEnv *env); - -JNIEXPORT jclass JNICALL -JNU_ClassObject(JNIEnv *env); - -JNIEXPORT jclass JNICALL -JNU_ClassThrowable(JNIEnv *env); - /* Copy count number of arguments from src to dst. Array bounds * and ArrayStoreException are checked. */ @@ -246,36 +207,6 @@ const char *classname, const char *name, const char *sig); -JNIEXPORT void JNICALL -JNU_SetStaticFieldByName(JNIEnv *env, - jboolean *hasException, - const char *classname, - const char *name, - const char *sig, - ...); - - -/* - * Calls the .equals method. - */ -JNIEXPORT jboolean JNICALL -JNU_Equals(JNIEnv *env, jobject object1, jobject object2); - - -/************************************************************************ - * Thread calls - * - * Convenience thread-related calls on the java.lang.Object class. - */ - -JNIEXPORT void JNICALL -JNU_MonitorWait(JNIEnv *env, jobject object, jlong timeout); - -JNIEXPORT void JNICALL -JNU_Notify(JNIEnv *env, jobject object); - -JNIEXPORT void JNICALL -JNU_NotifyAll(JNIEnv *env, jobject object); /************************************************************************ @@ -349,19 +280,15 @@ } \ } while (0) #endif /* __cplusplus */ + /************************************************************************ * Debugging utilities */ -JNIEXPORT void JNICALL -JNU_PrintString(JNIEnv *env, char *hdr, jstring string); - -JNIEXPORT void JNICALL -JNU_PrintClass(JNIEnv *env, char *hdr, jobject object); - JNIEXPORT jstring JNICALL JNU_ToString(JNIEnv *env, jobject object); + /* * Package shorthand for use by native libraries */ @@ -402,8 +329,6 @@ FAST_UTF_8 }; -int getFastEncoding(); - JNIEXPORT void InitializeEncoding(JNIEnv *env, const char *name); void* getProcessHandle(); diff -r 227ddf1ff93d -r 55a8d95c7787 src/java.base/unix/native/libjava/jdk_util_md.c --- a/src/java.base/unix/native/libjava/jdk_util_md.c Tue Oct 08 09:33:57 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2004, 2005, 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 - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jdk_util.h" - -int JDK_InitJvmHandle() { - /* nop */ - return 1; -} - -void* JDK_FindJvmEntry(const char* name) { - return dlsym(RTLD_DEFAULT, name); -} diff -r 227ddf1ff93d -r 55a8d95c7787 src/java.base/windows/native/libjava/jdk_util_md.c --- a/src/java.base/windows/native/libjava/jdk_util_md.c Tue Oct 08 09:33:57 2019 +0200 +++ b/src/java.base/windows/native/libjava/jdk_util_md.c Tue Oct 08 10:24:22 2019 +0200 @@ -28,17 +28,6 @@ #define JVM_DLL "jvm.dll" -static HMODULE jvm_handle = NULL; - -int JDK_InitJvmHandle() { - jvm_handle = GetModuleHandle(JVM_DLL); - return (jvm_handle != NULL); -} - -void* JDK_FindJvmEntry(const char* name) { - return (void*) GetProcAddress(jvm_handle, name); -} - JNIEXPORT HMODULE JDK_LoadSystemLibrary(const char* name) { HMODULE handle = NULL; char path[MAX_PATH];