Skip to content

Commit fba19ff

Browse files
committed
8230043: Lazily load libverify
8230140: Remove unused mutex and monitor declarations Reviewed-by: hseigel, erikj, alanb, dholmes
1 parent 204ed44 commit fba19ff

12 files changed

Lines changed: 73 additions & 151 deletions

File tree

make/lib/CoreLibraries.gmk

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
# questions.
2424
#
2525

26-
WIN_VERIFY_LIB := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libverify/verify.lib
27-
2826
# Hook to include the corresponding custom file, if present.
2927
$(eval $(call IncludeCustomExtension, lib/CoreLibraries.gmk))
3028

@@ -110,14 +108,14 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJAVA, \
110108
LDFLAGS_macosx := -L$(SUPPORT_OUTPUTDIR)/native/$(MODULE)/, \
111109
LDFLAGS_windows := -delayload:shell32.dll, \
112110
LIBS := $(BUILD_LIBFDLIBM_TARGET), \
113-
LIBS_unix := -ljvm -lverify, \
111+
LIBS_unix := -ljvm, \
114112
LIBS_linux := $(LIBDL), \
115113
LIBS_solaris := -lsocket -lnsl -lscf $(LIBDL), \
116114
LIBS_aix := $(LIBDL) $(LIBM),\
117115
LIBS_macosx := -framework CoreFoundation \
118116
-framework Foundation \
119117
-framework SystemConfiguration, \
120-
LIBS_windows := jvm.lib $(WIN_VERIFY_LIB) \
118+
LIBS_windows := jvm.lib \
121119
shell32.lib delayimp.lib \
122120
advapi32.lib version.lib, \
123121
))

src/hotspot/share/classfile/verifier.cpp

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,39 @@
6363
#define STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION 52
6464
#define MAX_ARRAY_DIMENSIONS 255
6565

66-
// Access to external entry for VerifyClassCodes - old byte code verifier
66+
// Access to external entry for VerifyClassForMajorVersion - old byte code verifier
6767

6868
extern "C" {
69-
typedef jboolean (*verify_byte_codes_fn_t)(JNIEnv *, jclass, char *, jint);
70-
typedef jboolean (*verify_byte_codes_fn_new_t)(JNIEnv *, jclass, char *, jint, jint);
69+
typedef jboolean (*verify_byte_codes_fn_t)(JNIEnv *, jclass, char *, jint, jint);
7170
}
7271

73-
static void* volatile _verify_byte_codes_fn = NULL;
72+
static verify_byte_codes_fn_t volatile _verify_byte_codes_fn = NULL;
7473

75-
static volatile jint _is_new_verify_byte_codes_fn = (jint) true;
74+
static verify_byte_codes_fn_t verify_byte_codes_fn() {
7675

77-
static void* verify_byte_codes_fn() {
78-
if (OrderAccess::load_acquire(&_verify_byte_codes_fn) == NULL) {
79-
void *lib_handle = os::native_java_library();
80-
void *func = os::dll_lookup(lib_handle, "VerifyClassCodesForMajorVersion");
81-
OrderAccess::release_store(&_verify_byte_codes_fn, func);
82-
if (func == NULL) {
83-
_is_new_verify_byte_codes_fn = false;
84-
func = os::dll_lookup(lib_handle, "VerifyClassCodes");
85-
OrderAccess::release_store(&_verify_byte_codes_fn, func);
86-
}
87-
}
88-
return (void*)_verify_byte_codes_fn;
76+
if (_verify_byte_codes_fn != NULL)
77+
return _verify_byte_codes_fn;
78+
79+
MutexLocker locker(Verify_lock);
80+
81+
if (_verify_byte_codes_fn != NULL)
82+
return _verify_byte_codes_fn;
83+
84+
// Load verify dll
85+
char buffer[JVM_MAXPATHLEN];
86+
char ebuf[1024];
87+
if (!os::dll_locate_lib(buffer, sizeof(buffer), Arguments::get_dll_dir(), "verify"))
88+
return NULL; // Caller will throw VerifyError
89+
90+
void *lib_handle = os::dll_load(buffer, ebuf, sizeof(ebuf));
91+
if (lib_handle == NULL)
92+
return NULL; // Caller will throw VerifyError
93+
94+
void *fn = os::dll_lookup(lib_handle, "VerifyClassForMajorVersion");
95+
if (fn == NULL)
96+
return NULL; // Caller will throw VerifyError
97+
98+
return _verify_byte_codes_fn = CAST_TO_FN_PTR(verify_byte_codes_fn_t, fn);
8999
}
90100

91101

@@ -282,7 +292,7 @@ Symbol* Verifier::inference_verify(
282292
JavaThread* thread = (JavaThread*)THREAD;
283293
JNIEnv *env = thread->jni_environment();
284294

285-
void* verify_func = verify_byte_codes_fn();
295+
verify_byte_codes_fn_t verify_func = verify_byte_codes_fn();
286296

287297
if (verify_func == NULL) {
288298
jio_snprintf(message, message_len, "Could not link verifier");
@@ -301,16 +311,7 @@ Symbol* Verifier::inference_verify(
301311
// ThreadToNativeFromVM takes care of changing thread_state, so safepoint
302312
// code knows that we have left the VM
303313

304-
if (_is_new_verify_byte_codes_fn) {
305-
verify_byte_codes_fn_new_t func =
306-
CAST_TO_FN_PTR(verify_byte_codes_fn_new_t, verify_func);
307-
result = (*func)(env, cls, message, (int)message_len,
308-
klass->major_version());
309-
} else {
310-
verify_byte_codes_fn_t func =
311-
CAST_TO_FN_PTR(verify_byte_codes_fn_t, verify_func);
312-
result = (*func)(env, cls, message, (int)message_len);
313-
}
314+
result = (*verify_func)(env, cls, message, (int)message_len, klass->major_version());
314315
}
315316

316317
JNIHandles::destroy_local(cls);

src/hotspot/share/include/jvm.h

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,19 +1043,6 @@ JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2);
10431043
/* Get classfile constants */
10441044
#include "classfile_constants.h"
10451045

1046-
/*
1047-
* A function defined by the byte-code verifier and called by the VM.
1048-
* This is not a function implemented in the VM.
1049-
*
1050-
* Returns JNI_FALSE if verification fails. A detailed error message
1051-
* will be places in msg_buf, whose length is specified by buf_len.
1052-
*/
1053-
typedef jboolean (*verifier_fn_t)(JNIEnv *env,
1054-
jclass cb,
1055-
char * msg_buf,
1056-
jint buf_len);
1057-
1058-
10591046
/*
10601047
* Support for a VM-independent class format checker.
10611048
*/
@@ -1086,28 +1073,6 @@ typedef struct {
10861073

10871074
typedef jstring (*to_java_string_fn_t)(JNIEnv *env, char *str);
10881075

1089-
typedef char *(*to_c_string_fn_t)(JNIEnv *env, jstring s, jboolean *b);
1090-
1091-
/* This is the function defined in libjava.so that performs class
1092-
* format checks. This functions fills in size information about
1093-
* the class file and returns:
1094-
*
1095-
* 0: good
1096-
* -1: out of memory
1097-
* -2: bad format
1098-
* -3: unsupported version
1099-
* -4: bad class name
1100-
*/
1101-
1102-
typedef jint (*check_format_fn_t)(char *class_name,
1103-
unsigned char *data,
1104-
unsigned int data_size,
1105-
class_size_info *class_size,
1106-
char *message_buffer,
1107-
jint buffer_length,
1108-
jboolean measure_only,
1109-
jboolean check_relaxed);
1110-
11111076
#define JVM_RECOGNIZED_CLASS_MODIFIERS (JVM_ACC_PUBLIC | \
11121077
JVM_ACC_FINAL | \
11131078
JVM_ACC_SUPER | \

src/hotspot/share/runtime/mutexLocker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ Mutex* TouchedMethodLog_lock = NULL;
6666
Mutex* RetData_lock = NULL;
6767
Monitor* VMOperationQueue_lock = NULL;
6868
Monitor* VMOperationRequest_lock = NULL;
69-
Monitor* SerializePage_lock = NULL;
7069
Monitor* Threads_lock = NULL;
7170
Mutex* NonJavaThreadsList_lock = NULL;
7271
Mutex* NonJavaThreadsListSync_lock = NULL;
@@ -118,6 +117,7 @@ Mutex* Management_lock = NULL;
118117
Monitor* Service_lock = NULL;
119118
Monitor* PeriodicTask_lock = NULL;
120119
Monitor* RedefineClasses_lock = NULL;
120+
Mutex* Verify_lock = NULL;
121121

122122
#if INCLUDE_JFR
123123
Mutex* JfrStacktrace_lock = NULL;
@@ -298,6 +298,7 @@ void mutex_init() {
298298
def(CompileThread_lock , PaddedMonitor, nonleaf+5, false, _safepoint_check_always);
299299
def(PeriodicTask_lock , PaddedMonitor, nonleaf+5, true, _safepoint_check_always);
300300
def(RedefineClasses_lock , PaddedMonitor, nonleaf+5, true, _safepoint_check_always);
301+
def(Verify_lock , PaddedMutex, nonleaf+5, true, _safepoint_check_always);
301302

302303
if (WhiteBoxAPI) {
303304
def(Compilation_lock , PaddedMonitor, leaf, false, _safepoint_check_never);

src/hotspot/share/runtime/mutexLocker.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ extern Mutex* Debug3_lock;
103103
extern Mutex* RawMonitor_lock;
104104
extern Mutex* PerfDataMemAlloc_lock; // a lock on the allocator for PerfData memory for performance data
105105
extern Mutex* PerfDataManager_lock; // a long on access to PerfDataManager resources
106-
extern Mutex* ParkerFreeList_lock;
107106
extern Mutex* OopMapCacheAlloc_lock; // protects allocation of oop_map caches
108107

109108
extern Mutex* FreeList_lock; // protects the free region list during safepoints
@@ -114,6 +113,7 @@ extern Mutex* Management_lock; // a lock used to serialize JVM
114113
extern Monitor* Service_lock; // a lock used for service thread operation
115114
extern Monitor* PeriodicTask_lock; // protects the periodic task structure
116115
extern Monitor* RedefineClasses_lock; // locks classes from parallel redefinition
116+
extern Mutex* Verify_lock; // synchronize initialization of verify library
117117
extern Monitor* ThreadsSMRDelete_lock; // Used by ThreadsSMRSupport to take pressure off the Threads_lock
118118
extern Mutex* ThreadIdTableCreate_lock; // Used by ThreadIdTable to lazily create the thread id table
119119
extern Mutex* SharedDecoder_lock; // serializes access to the decoder during normal (not error reporting) use

src/hotspot/share/runtime/os.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,14 +536,6 @@ void* os::native_java_library() {
536536
char buffer[JVM_MAXPATHLEN];
537537
char ebuf[1024];
538538

539-
// Try to load verify dll first. In 1.3 java dll depends on it and is not
540-
// always able to find it when the loading executable is outside the JDK.
541-
// In order to keep working with 1.2 we ignore any loading errors.
542-
if (dll_locate_lib(buffer, sizeof(buffer), Arguments::get_dll_dir(),
543-
"verify")) {
544-
dll_load(buffer, ebuf, sizeof(ebuf));
545-
}
546-
547539
// Load java dll
548540
if (dll_locate_lib(buffer, sizeof(buffer), Arguments::get_dll_dir(),
549541
"java")) {

src/java.base/share/native/libjava/Class.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,9 @@
3535
#include "jni.h"
3636
#include "jni_util.h"
3737
#include "jvm.h"
38+
#include "check_classname.h"
3839
#include "java_lang_Class.h"
3940

40-
/* defined in libverify.so/verify.dll (src file common/check_format.c) */
41-
extern jboolean VerifyClassname(char *utf_name, jboolean arrayAllowed);
42-
extern jboolean VerifyFixClassname(char *utf_name);
43-
4441
#define OBJ "Ljava/lang/Object;"
4542
#define CLS "Ljava/lang/Class;"
4643
#define CPL "Ljdk/internal/reflect/ConstantPool;"
@@ -123,14 +120,14 @@ Java_java_lang_Class_forName0(JNIEnv *env, jclass this, jstring classname,
123120
}
124121
(*env)->GetStringUTFRegion(env, classname, 0, unicode_len, clname);
125122

126-
if (VerifyFixClassname(clname) == JNI_TRUE) {
123+
if (verifyFixClassname(clname) == JNI_TRUE) {
127124
/* slashes present in clname, use name b4 translation for exception */
128125
(*env)->GetStringUTFRegion(env, classname, 0, unicode_len, clname);
129126
JNU_ThrowClassNotFoundException(env, clname);
130127
goto done;
131128
}
132129

133-
if (!VerifyClassname(clname, JNI_TRUE)) { /* expects slashed name */
130+
if (!verifyClassname(clname, JNI_TRUE)) { /* expects slashed name */
134131
JNU_ThrowClassNotFoundException(env, clname);
135132
goto done;
136133
}

src/java.base/share/native/libjava/ClassLoader.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,11 @@
3030
#include "jni_util.h"
3131
#include "jlong.h"
3232
#include "jvm.h"
33+
#include "check_classname.h"
3334
#include "java_lang_ClassLoader.h"
3435
#include "java_lang_ClassLoader_NativeLibrary.h"
3536
#include <string.h>
3637

37-
/* defined in libverify.so/verify.dll (src file common/check_format.c) */
38-
extern jboolean VerifyClassname(char *utf_name, jboolean arrayAllowed);
39-
extern jboolean VerifyFixClassname(char *utf_name);
40-
4138
static JNINativeMethod methods[] = {
4239
{"retrieveDirectives", "()Ljava/lang/AssertionStatusDirectives;", (void *)&JVM_AssertionStatusDirectives}
4340
};
@@ -120,7 +117,7 @@ Java_java_lang_ClassLoader_defineClass1(JNIEnv *env,
120117
if (utfName == NULL) {
121118
goto free_body;
122119
}
123-
VerifyFixClassname(utfName);
120+
fixClassname(utfName);
124121
} else {
125122
utfName = NULL;
126123
}
@@ -185,7 +182,7 @@ Java_java_lang_ClassLoader_defineClass2(JNIEnv *env,
185182
JNU_ThrowOutOfMemoryError(env, NULL);
186183
return result;
187184
}
188-
VerifyFixClassname(utfName);
185+
fixClassname(utfName);
189186
} else {
190187
utfName = NULL;
191188
}
@@ -231,9 +228,9 @@ Java_java_lang_ClassLoader_findBootstrapClass(JNIEnv *env, jobject loader,
231228
JNU_ThrowOutOfMemoryError(env, NULL);
232229
return NULL;
233230
}
234-
VerifyFixClassname(clname);
231+
fixClassname(clname);
235232

236-
if (!VerifyClassname(clname, JNI_TRUE)) { /* expects slashed name */
233+
if (!verifyClassname(clname, JNI_TRUE)) { /* expects slashed name */
237234
goto done;
238235
}
239236

src/java.base/share/native/libverify/check_format.c renamed to src/java.base/share/native/libjava/check_classname.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,6 +31,7 @@
3131

3232
#include "jni.h"
3333
#include "jvm.h"
34+
#include "check_classname.h"
3435

3536
typedef unsigned short unicode;
3637

@@ -223,16 +224,13 @@ skip_over_field_signature(char *name, jboolean void_okay,
223224
return 0;
224225
}
225226

226-
227-
/* Used in java/lang/Class.c */
228227
/* Determine if the specified name is legal
229228
* UTF name for a classname.
230229
*
231230
* Note that this routine expects the internal form of qualified classes:
232231
* the dots should have been replaced by slashes.
233232
*/
234-
JNIEXPORT jboolean
235-
VerifyClassname(char *name, jboolean allowArrayClass)
233+
jboolean verifyClassname(char *name, jboolean allowArrayClass)
236234
{
237235
size_t s = strlen(name);
238236
assert(s <= UINT_MAX);
@@ -254,10 +252,9 @@ VerifyClassname(char *name, jboolean allowArrayClass)
254252
}
255253

256254
/*
257-
* Translates '.' to '/'. Returns JNI_TRUE is any / were present.
255+
* Translates '.' to '/'. Returns JNI_TRUE if any / were present.
258256
*/
259-
JNIEXPORT jboolean
260-
VerifyFixClassname(char *name)
257+
jboolean verifyFixClassname(char *name)
261258
{
262259
char *p = name;
263260
jboolean slashesFound = JNI_FALSE;
@@ -276,3 +273,20 @@ VerifyFixClassname(char *name)
276273

277274
return slashesFound && valid != 0;
278275
}
276+
277+
/*
278+
* Translates '.' to '/'.
279+
*/
280+
void fixClassname(char *name)
281+
{
282+
char *p = name;
283+
int valid = 1;
284+
285+
while (valid != 0 && *p != '\0') {
286+
if (*p == '.') {
287+
*p++ = '/';
288+
} else {
289+
next_utf2unicode(&p, &valid);
290+
}
291+
}
292+
}

0 commit comments

Comments
 (0)