37 #include "memory/oopFactory.hpp"
38 #include "memory/resourceArea.hpp"
39 #include "oops/instanceKlass.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "oops/typeArrayOop.hpp"
42 #include "prims/jvm.h"
43 #include "runtime/fieldDescriptor.hpp"
44 #include "runtime/handles.inline.hpp"
45 #include "runtime/interfaceSupport.hpp"
46 #include "runtime/javaCalls.hpp"
47 #include "runtime/orderAccess.inline.hpp"
48 #include "runtime/os.hpp"
49 #include "runtime/thread.hpp"
50 #include "services/threadService.hpp"
51 #include "utilities/bytes.hpp"
52 #include "logging/log.hpp"
53
54 #define NOFAILOVER_MAJOR_VERSION 51
55 #define NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION 51
56 #define STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION 52
57
58 // Access to external entry for VerifyClassCodes - old byte code verifier
59
60 extern "C" {
61 typedef jboolean (*verify_byte_codes_fn_t)(JNIEnv *, jclass, char *, jint);
62 typedef jboolean (*verify_byte_codes_fn_new_t)(JNIEnv *, jclass, char *, jint, jint);
63 }
64
65 static void* volatile _verify_byte_codes_fn = NULL;
66
67 static volatile jint _is_new_verify_byte_codes_fn = (jint) true;
68
69 static void* verify_byte_codes_fn() {
70 if (OrderAccess::load_ptr_acquire(&_verify_byte_codes_fn) == NULL) {
71 void *lib_handle = os::native_java_library();
72 void *func = os::dll_lookup(lib_handle, "VerifyClassCodesForMajorVersion");
73 OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func);
74 if (func == NULL) {
75 _is_new_verify_byte_codes_fn = false;
76 func = os::dll_lookup(lib_handle, "VerifyClassCodes");
2914 // from_bt[index] contains the array signature which has a length of 2
2915 Symbol* sig = create_temporary_symbol(
2916 from_bt[index], 2, CHECK_(VerificationType::bogus_type()));
2917 return VerificationType::reference_type(sig);
2918 }
2919
2920 void ClassVerifier::verify_anewarray(
2921 u2 bci, u2 index, const constantPoolHandle& cp,
2922 StackMapFrame* current_frame, TRAPS) {
2923 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
2924 current_frame->pop_stack(
2925 VerificationType::integer_type(), CHECK_VERIFY(this));
2926
2927 if (was_recursively_verified()) return;
2928 VerificationType component_type =
2929 cp_index_to_type(index, cp, CHECK_VERIFY(this));
2930 int length;
2931 char* arr_sig_str;
2932 if (component_type.is_array()) { // it's an array
2933 const char* component_name = component_type.name()->as_utf8();
2934 // add one dimension to component
2935 length = (int)strlen(component_name) + 1;
2936 arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length);
2937 arr_sig_str[0] = '[';
2938 strncpy(&arr_sig_str[1], component_name, length - 1);
2939 } else { // it's an object or interface
2940 const char* component_name = component_type.name()->as_utf8();
2941 // add one dimension to component with 'L' prepended and ';' postpended.
2942 length = (int)strlen(component_name) + 3;
2943 arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length);
2944 arr_sig_str[0] = '[';
2945 arr_sig_str[1] = 'L';
2946 strncpy(&arr_sig_str[2], component_name, length - 2);
2947 arr_sig_str[length - 1] = ';';
2948 }
2949 Symbol* arr_sig = create_temporary_symbol(
2950 arr_sig_str, length, CHECK_VERIFY(this));
2951 VerificationType new_array_type = VerificationType::reference_type(arr_sig);
2952 current_frame->push_stack(new_array_type, CHECK_VERIFY(this));
2953 }
|
37 #include "memory/oopFactory.hpp"
38 #include "memory/resourceArea.hpp"
39 #include "oops/instanceKlass.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "oops/typeArrayOop.hpp"
42 #include "prims/jvm.h"
43 #include "runtime/fieldDescriptor.hpp"
44 #include "runtime/handles.inline.hpp"
45 #include "runtime/interfaceSupport.hpp"
46 #include "runtime/javaCalls.hpp"
47 #include "runtime/orderAccess.inline.hpp"
48 #include "runtime/os.hpp"
49 #include "runtime/thread.hpp"
50 #include "services/threadService.hpp"
51 #include "utilities/bytes.hpp"
52 #include "logging/log.hpp"
53
54 #define NOFAILOVER_MAJOR_VERSION 51
55 #define NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION 51
56 #define STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION 52
57 #define MAX_ARRAY_DIMENSIONS 255
58
59 // Access to external entry for VerifyClassCodes - old byte code verifier
60
61 extern "C" {
62 typedef jboolean (*verify_byte_codes_fn_t)(JNIEnv *, jclass, char *, jint);
63 typedef jboolean (*verify_byte_codes_fn_new_t)(JNIEnv *, jclass, char *, jint, jint);
64 }
65
66 static void* volatile _verify_byte_codes_fn = NULL;
67
68 static volatile jint _is_new_verify_byte_codes_fn = (jint) true;
69
70 static void* verify_byte_codes_fn() {
71 if (OrderAccess::load_ptr_acquire(&_verify_byte_codes_fn) == NULL) {
72 void *lib_handle = os::native_java_library();
73 void *func = os::dll_lookup(lib_handle, "VerifyClassCodesForMajorVersion");
74 OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func);
75 if (func == NULL) {
76 _is_new_verify_byte_codes_fn = false;
77 func = os::dll_lookup(lib_handle, "VerifyClassCodes");
2915 // from_bt[index] contains the array signature which has a length of 2
2916 Symbol* sig = create_temporary_symbol(
2917 from_bt[index], 2, CHECK_(VerificationType::bogus_type()));
2918 return VerificationType::reference_type(sig);
2919 }
2920
2921 void ClassVerifier::verify_anewarray(
2922 u2 bci, u2 index, const constantPoolHandle& cp,
2923 StackMapFrame* current_frame, TRAPS) {
2924 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
2925 current_frame->pop_stack(
2926 VerificationType::integer_type(), CHECK_VERIFY(this));
2927
2928 if (was_recursively_verified()) return;
2929 VerificationType component_type =
2930 cp_index_to_type(index, cp, CHECK_VERIFY(this));
2931 int length;
2932 char* arr_sig_str;
2933 if (component_type.is_array()) { // it's an array
2934 const char* component_name = component_type.name()->as_utf8();
2935 // Check for more than MAX_ARRAY_DIMENSIONS
2936 int dims = 0;
2937 while (component_name[dims] == '[') {
2938 dims++;
2939 }
2940 if (dims >= MAX_ARRAY_DIMENSIONS) {
2941 verify_error(ErrorContext::bad_code(bci),
2942 "Illegal anewarray instruction, array has more than 255 dimensions");
2943 }
2944 // add one dimension to component
2945 length = (int)strlen(component_name) + 1;
2946 arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length);
2947 arr_sig_str[0] = '[';
2948 strncpy(&arr_sig_str[1], component_name, length - 1);
2949 } else { // it's an object or interface
2950 const char* component_name = component_type.name()->as_utf8();
2951 // add one dimension to component with 'L' prepended and ';' postpended.
2952 length = (int)strlen(component_name) + 3;
2953 arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length);
2954 arr_sig_str[0] = '[';
2955 arr_sig_str[1] = 'L';
2956 strncpy(&arr_sig_str[2], component_name, length - 2);
2957 arr_sig_str[length - 1] = ';';
2958 }
2959 Symbol* arr_sig = create_temporary_symbol(
2960 arr_sig_str, length, CHECK_VERIFY(this));
2961 VerificationType new_array_type = VerificationType::reference_type(arr_sig);
2962 current_frame->push_stack(new_array_type, CHECK_VERIFY(this));
2963 }
|