46 #include "oops/oop.inline.hpp"
47 #include "oops/typeArrayOop.hpp"
48 #include "runtime/fieldDescriptor.hpp"
49 #include "runtime/handles.inline.hpp"
50 #include "runtime/interfaceSupport.inline.hpp"
51 #include "runtime/javaCalls.hpp"
52 #include "runtime/jniHandles.inline.hpp"
53 #include "runtime/orderAccess.hpp"
54 #include "runtime/os.hpp"
55 #include "runtime/safepointVerifiers.hpp"
56 #include "runtime/thread.hpp"
57 #include "services/threadService.hpp"
58 #include "utilities/align.hpp"
59 #include "utilities/bytes.hpp"
60
61 #define NOFAILOVER_MAJOR_VERSION 51
62 #define NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION 51
63 #define STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION 52
64 #define MAX_ARRAY_DIMENSIONS 255
65
66 // Access to external entry for VerifyClassCodes - old byte code verifier
67
68 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);
71 }
72
73 static void* volatile _verify_byte_codes_fn = NULL;
74
75 static volatile jint _is_new_verify_byte_codes_fn = (jint) true;
76
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;
89 }
90
91
92 // Methods in Verifier
93
94 bool Verifier::should_verify_for(oop class_loader, bool should_verify_class) {
95 return (class_loader == NULL || !should_verify_class) ?
96 BytecodeVerificationLocal : BytecodeVerificationRemote;
97 }
98
99 bool Verifier::relax_access_for(oop loader) {
100 bool trusted = java_lang_ClassLoader::is_trusted_loader(loader);
101 bool need_verify =
102 // verifyAll
103 (BytecodeVerificationLocal && BytecodeVerificationRemote) ||
104 // verifyRemote
105 (!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted);
106 return !need_verify;
107 }
108
265 // already been rewritten to contain constant pool cache indices,
266 // which the verifier can't understand.
267 // Shared classes shouldn't have stackmaps either.
268 !klass->is_shared() &&
269
270 // As of the fix for 4486457 we disable verification for all of the
271 // dynamically-generated bytecodes associated with the 1.4
272 // reflection implementation, not just those associated with
273 // jdk/internal/reflect/SerializationConstructorAccessor.
274 // NOTE: this is called too early in the bootstrapping process to be
275 // guarded by Universe::is_gte_jdk14x_version().
276 // Also for lambda generated code, gte jdk8
277 (!is_reflect));
278 }
279
280 Symbol* Verifier::inference_verify(
281 InstanceKlass* klass, char* message, size_t message_len, TRAPS) {
282 JavaThread* thread = (JavaThread*)THREAD;
283 JNIEnv *env = thread->jni_environment();
284
285 void* verify_func = verify_byte_codes_fn();
286
287 if (verify_func == NULL) {
288 jio_snprintf(message, message_len, "Could not link verifier");
289 return vmSymbols::java_lang_VerifyError();
290 }
291
292 ResourceMark rm(THREAD);
293 log_info(verification)("Verifying class %s with old format", klass->external_name());
294
295 jclass cls = (jclass) JNIHandles::make_local(env, klass->java_mirror());
296 jint result;
297
298 {
299 HandleMark hm(thread);
300 ThreadToNativeFromVM ttn(thread);
301 // ThreadToNativeFromVM takes care of changing thread_state, so safepoint
302 // code knows that we have left the VM
303
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 }
315
316 JNIHandles::destroy_local(cls);
317
318 // These numbers are chosen so that VerifyClassCodes interface doesn't need
319 // to be changed (still return jboolean (unsigned char)), and result is
320 // 1 when verification is passed.
321 if (result == 0) {
322 return vmSymbols::java_lang_VerifyError();
323 } else if (result == 1) {
324 return NULL; // verified.
325 } else if (result == 2) {
326 THROW_MSG_(vmSymbols::java_lang_OutOfMemoryError(), message, NULL);
327 } else if (result == 3) {
328 return vmSymbols::java_lang_ClassFormatError();
329 } else {
330 ShouldNotReachHere();
331 return NULL;
332 }
333 }
|
46 #include "oops/oop.inline.hpp"
47 #include "oops/typeArrayOop.hpp"
48 #include "runtime/fieldDescriptor.hpp"
49 #include "runtime/handles.inline.hpp"
50 #include "runtime/interfaceSupport.inline.hpp"
51 #include "runtime/javaCalls.hpp"
52 #include "runtime/jniHandles.inline.hpp"
53 #include "runtime/orderAccess.hpp"
54 #include "runtime/os.hpp"
55 #include "runtime/safepointVerifiers.hpp"
56 #include "runtime/thread.hpp"
57 #include "services/threadService.hpp"
58 #include "utilities/align.hpp"
59 #include "utilities/bytes.hpp"
60
61 #define NOFAILOVER_MAJOR_VERSION 51
62 #define NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION 51
63 #define STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION 52
64 #define MAX_ARRAY_DIMENSIONS 255
65
66 // Access to external entry for VerifyClassForMajorVersion - old byte code verifier
67
68 extern "C" {
69 typedef jboolean (*verify_byte_codes_fn_t)(JNIEnv *, jclass, char *, jint, jint);
70 }
71
72 static verify_byte_codes_fn_t volatile _verify_byte_codes_fn = NULL;
73
74 static verify_byte_codes_fn_t verify_byte_codes_fn() {
75
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);
99 }
100
101
102 // Methods in Verifier
103
104 bool Verifier::should_verify_for(oop class_loader, bool should_verify_class) {
105 return (class_loader == NULL || !should_verify_class) ?
106 BytecodeVerificationLocal : BytecodeVerificationRemote;
107 }
108
109 bool Verifier::relax_access_for(oop loader) {
110 bool trusted = java_lang_ClassLoader::is_trusted_loader(loader);
111 bool need_verify =
112 // verifyAll
113 (BytecodeVerificationLocal && BytecodeVerificationRemote) ||
114 // verifyRemote
115 (!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted);
116 return !need_verify;
117 }
118
275 // already been rewritten to contain constant pool cache indices,
276 // which the verifier can't understand.
277 // Shared classes shouldn't have stackmaps either.
278 !klass->is_shared() &&
279
280 // As of the fix for 4486457 we disable verification for all of the
281 // dynamically-generated bytecodes associated with the 1.4
282 // reflection implementation, not just those associated with
283 // jdk/internal/reflect/SerializationConstructorAccessor.
284 // NOTE: this is called too early in the bootstrapping process to be
285 // guarded by Universe::is_gte_jdk14x_version().
286 // Also for lambda generated code, gte jdk8
287 (!is_reflect));
288 }
289
290 Symbol* Verifier::inference_verify(
291 InstanceKlass* klass, char* message, size_t message_len, TRAPS) {
292 JavaThread* thread = (JavaThread*)THREAD;
293 JNIEnv *env = thread->jni_environment();
294
295 verify_byte_codes_fn_t verify_func = verify_byte_codes_fn();
296
297 if (verify_func == NULL) {
298 jio_snprintf(message, message_len, "Could not link verifier");
299 return vmSymbols::java_lang_VerifyError();
300 }
301
302 ResourceMark rm(THREAD);
303 log_info(verification)("Verifying class %s with old format", klass->external_name());
304
305 jclass cls = (jclass) JNIHandles::make_local(env, klass->java_mirror());
306 jint result;
307
308 {
309 HandleMark hm(thread);
310 ThreadToNativeFromVM ttn(thread);
311 // ThreadToNativeFromVM takes care of changing thread_state, so safepoint
312 // code knows that we have left the VM
313
314 result = (*verify_func)(env, cls, message, (int)message_len, klass->major_version());
315 }
316
317 JNIHandles::destroy_local(cls);
318
319 // These numbers are chosen so that VerifyClassCodes interface doesn't need
320 // to be changed (still return jboolean (unsigned char)), and result is
321 // 1 when verification is passed.
322 if (result == 0) {
323 return vmSymbols::java_lang_VerifyError();
324 } else if (result == 1) {
325 return NULL; // verified.
326 } else if (result == 2) {
327 THROW_MSG_(vmSymbols::java_lang_OutOfMemoryError(), message, NULL);
328 } else if (result == 3) {
329 return vmSymbols::java_lang_ClassFormatError();
330 } else {
331 ShouldNotReachHere();
332 return NULL;
333 }
334 }
|