59 // Implementation of Method |
59 // Implementation of Method |
60 |
60 |
61 Method* Method::allocate(ClassLoaderData* loader_data, |
61 Method* Method::allocate(ClassLoaderData* loader_data, |
62 int byte_code_size, |
62 int byte_code_size, |
63 AccessFlags access_flags, |
63 AccessFlags access_flags, |
64 int compressed_line_number_size, |
64 InlineTableSizes* sizes, |
65 int localvariable_table_length, |
|
66 int exception_table_length, |
|
67 int checked_exceptions_length, |
|
68 int method_parameters_length, |
|
69 u2 generic_signature_index, |
|
70 ConstMethod::MethodType method_type, |
65 ConstMethod::MethodType method_type, |
71 TRAPS) { |
66 TRAPS) { |
72 assert(!access_flags.is_native() || byte_code_size == 0, |
67 assert(!access_flags.is_native() || byte_code_size == 0, |
73 "native methods should not contain byte codes"); |
68 "native methods should not contain byte codes"); |
74 ConstMethod* cm = ConstMethod::allocate(loader_data, |
69 ConstMethod* cm = ConstMethod::allocate(loader_data, |
75 byte_code_size, |
70 byte_code_size, |
76 compressed_line_number_size, |
71 sizes, |
77 localvariable_table_length, |
|
78 exception_table_length, |
|
79 checked_exceptions_length, |
|
80 method_parameters_length, |
|
81 generic_signature_index, |
|
82 method_type, |
72 method_type, |
83 CHECK_NULL); |
73 CHECK_NULL); |
84 |
74 |
85 int size = Method::size(access_flags.is_native()); |
75 int size = Method::size(access_flags.is_native()); |
86 |
76 |
315 InstanceKlass* ik = (InstanceKlass*) k; |
305 InstanceKlass* ik = (InstanceKlass*) k; |
316 return ik->name(); |
306 return ik->name(); |
317 } |
307 } |
318 |
308 |
319 |
309 |
320 void Method::set_interpreter_kind() { |
|
321 int kind = Interpreter::method_kind(this); |
|
322 assert(kind != Interpreter::invalid, |
|
323 "interpreter entry must be valid"); |
|
324 set_interpreter_kind(kind); |
|
325 } |
|
326 |
|
327 |
|
328 // Attempt to return method oop to original state. Clear any pointers |
310 // Attempt to return method oop to original state. Clear any pointers |
329 // (to objects outside the shared spaces). We won't be able to predict |
311 // (to objects outside the shared spaces). We won't be able to predict |
330 // where they should point in a new JVM. Further initialize some |
312 // where they should point in a new JVM. Further initialize some |
331 // entries now in order allow them to be write protected later. |
313 // entries now in order allow them to be write protected later. |
332 |
314 |
333 void Method::remove_unshareable_info() { |
315 void Method::remove_unshareable_info() { |
334 unlink_method(); |
316 unlink_method(); |
335 set_interpreter_kind(); |
|
336 } |
317 } |
337 |
318 |
338 |
319 |
339 bool Method::was_executed_more_than(int n) { |
320 bool Method::was_executed_more_than(int n) { |
340 // Invocation counter is reset when the Method* is compiled. |
321 // Invocation counter is reset when the Method* is compiled. |
1043 if (must_be_static) flags_bits |= JVM_ACC_STATIC; |
1024 if (must_be_static) flags_bits |= JVM_ACC_STATIC; |
1044 assert((flags_bits & JVM_ACC_PUBLIC) == 0, "do not expose these methods"); |
1025 assert((flags_bits & JVM_ACC_PUBLIC) == 0, "do not expose these methods"); |
1045 |
1026 |
1046 methodHandle m; |
1027 methodHandle m; |
1047 { |
1028 { |
|
1029 InlineTableSizes sizes; |
1048 Method* m_oop = Method::allocate(loader_data, 0, |
1030 Method* m_oop = Method::allocate(loader_data, 0, |
1049 accessFlags_from(flags_bits), |
1031 accessFlags_from(flags_bits), &sizes, |
1050 0, 0, 0, 0, 0, 0, |
|
1051 ConstMethod::NORMAL, CHECK_(empty)); |
1032 ConstMethod::NORMAL, CHECK_(empty)); |
1052 m = methodHandle(THREAD, m_oop); |
1033 m = methodHandle(THREAD, m_oop); |
1053 } |
1034 } |
1054 m->set_constants(cp()); |
1035 m->set_constants(cp()); |
1055 m->set_name_index(_imcp_invoke_name); |
1036 m->set_name_index(_imcp_invoke_name); |
1094 u_char* new_compressed_linenumber_table, int new_compressed_linenumber_size, TRAPS) { |
1075 u_char* new_compressed_linenumber_table, int new_compressed_linenumber_size, TRAPS) { |
1095 // Code below does not work for native methods - they should never get rewritten anyway |
1076 // Code below does not work for native methods - they should never get rewritten anyway |
1096 assert(!m->is_native(), "cannot rewrite native methods"); |
1077 assert(!m->is_native(), "cannot rewrite native methods"); |
1097 // Allocate new Method* |
1078 // Allocate new Method* |
1098 AccessFlags flags = m->access_flags(); |
1079 AccessFlags flags = m->access_flags(); |
1099 u2 generic_signature_index = m->generic_signature_index(); |
1080 |
1100 int checked_exceptions_len = m->checked_exceptions_length(); |
1081 ConstMethod* cm = m->constMethod(); |
1101 int localvariable_len = m->localvariable_table_length(); |
1082 int checked_exceptions_len = cm->checked_exceptions_length(); |
1102 int exception_table_len = m->exception_table_length(); |
1083 int localvariable_len = cm->localvariable_table_length(); |
1103 int method_parameters_len = m->method_parameters_length(); |
1084 int exception_table_len = cm->exception_table_length(); |
|
1085 int method_parameters_len = cm->method_parameters_length(); |
|
1086 int method_annotations_len = cm->method_annotations_length(); |
|
1087 int parameter_annotations_len = cm->parameter_annotations_length(); |
|
1088 int type_annotations_len = cm->type_annotations_length(); |
|
1089 int default_annotations_len = cm->default_annotations_length(); |
|
1090 |
|
1091 InlineTableSizes sizes( |
|
1092 localvariable_len, |
|
1093 new_compressed_linenumber_size, |
|
1094 exception_table_len, |
|
1095 checked_exceptions_len, |
|
1096 method_parameters_len, |
|
1097 cm->generic_signature_index(), |
|
1098 method_annotations_len, |
|
1099 parameter_annotations_len, |
|
1100 type_annotations_len, |
|
1101 default_annotations_len, |
|
1102 0); |
1104 |
1103 |
1105 ClassLoaderData* loader_data = m->method_holder()->class_loader_data(); |
1104 ClassLoaderData* loader_data = m->method_holder()->class_loader_data(); |
1106 Method* newm_oop = Method::allocate(loader_data, |
1105 Method* newm_oop = Method::allocate(loader_data, |
1107 new_code_length, |
1106 new_code_length, |
1108 flags, |
1107 flags, |
1109 new_compressed_linenumber_size, |
1108 &sizes, |
1110 localvariable_len, |
|
1111 exception_table_len, |
|
1112 checked_exceptions_len, |
|
1113 method_parameters_len, |
|
1114 generic_signature_index, |
|
1115 m->method_type(), |
1109 m->method_type(), |
1116 CHECK_(methodHandle())); |
1110 CHECK_(methodHandle())); |
1117 methodHandle newm (THREAD, newm_oop); |
1111 methodHandle newm (THREAD, newm_oop); |
1118 int new_method_size = newm->method_size(); |
1112 int new_method_size = newm->method_size(); |
1119 |
1113 |
1309 if (WizardMode) signature()->print_symbol_on(st); |
1303 if (WizardMode) signature()->print_symbol_on(st); |
1310 else if (MethodHandles::is_signature_polymorphic(intrinsic_id())) |
1304 else if (MethodHandles::is_signature_polymorphic(intrinsic_id())) |
1311 MethodHandles::print_as_basic_type_signature_on(st, signature(), true); |
1305 MethodHandles::print_as_basic_type_signature_on(st, signature(), true); |
1312 } |
1306 } |
1313 |
1307 |
1314 // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array |
|
1315 static void reorder_based_on_method_index(Array<Method*>* methods, |
|
1316 Array<AnnotationArray*>* annotations, |
|
1317 GrowableArray<AnnotationArray*>* temp_array) { |
|
1318 if (annotations == NULL) { |
|
1319 return; |
|
1320 } |
|
1321 |
|
1322 int length = methods->length(); |
|
1323 int i; |
|
1324 // Copy to temp array |
|
1325 temp_array->clear(); |
|
1326 for (i = 0; i < length; i++) { |
|
1327 temp_array->append(annotations->at(i)); |
|
1328 } |
|
1329 |
|
1330 // Copy back using old method indices |
|
1331 for (i = 0; i < length; i++) { |
|
1332 Method* m = methods->at(i); |
|
1333 annotations->at_put(i, temp_array->at(m->method_idnum())); |
|
1334 } |
|
1335 } |
|
1336 |
|
1337 // Comparer for sorting an object array containing |
1308 // Comparer for sorting an object array containing |
1338 // Method*s. |
1309 // Method*s. |
1339 static int method_comparator(Method* a, Method* b) { |
1310 static int method_comparator(Method* a, Method* b) { |
1340 return a->name()->fast_compare(b->name()); |
1311 return a->name()->fast_compare(b->name()); |
1341 } |
1312 } |
1342 |
1313 |
1343 // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array |
1314 // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array |
1344 void Method::sort_methods(Array<Method*>* methods, |
1315 void Method::sort_methods(Array<Method*>* methods, bool idempotent) { |
1345 Array<AnnotationArray*>* methods_annotations, |
|
1346 Array<AnnotationArray*>* methods_parameter_annotations, |
|
1347 Array<AnnotationArray*>* methods_default_annotations, |
|
1348 Array<AnnotationArray*>* methods_type_annotations, |
|
1349 bool idempotent) { |
|
1350 int length = methods->length(); |
1316 int length = methods->length(); |
1351 if (length > 1) { |
1317 if (length > 1) { |
1352 bool do_annotations = false; |
|
1353 if (methods_annotations != NULL || |
|
1354 methods_parameter_annotations != NULL || |
|
1355 methods_default_annotations != NULL || |
|
1356 methods_type_annotations != NULL) { |
|
1357 do_annotations = true; |
|
1358 } |
|
1359 if (do_annotations) { |
|
1360 // Remember current method ordering so we can reorder annotations |
|
1361 for (int i = 0; i < length; i++) { |
|
1362 Method* m = methods->at(i); |
|
1363 m->set_method_idnum(i); |
|
1364 } |
|
1365 } |
|
1366 { |
1318 { |
1367 No_Safepoint_Verifier nsv; |
1319 No_Safepoint_Verifier nsv; |
1368 QuickSort::sort<Method*>(methods->data(), length, method_comparator, idempotent); |
1320 QuickSort::sort<Method*>(methods->data(), length, method_comparator, idempotent); |
1369 } |
1321 } |
1370 |
|
1371 // Sort annotations if necessary |
|
1372 assert(methods_annotations == NULL || methods_annotations->length() == methods->length(), ""); |
|
1373 assert(methods_parameter_annotations == NULL || methods_parameter_annotations->length() == methods->length(), ""); |
|
1374 assert(methods_default_annotations == NULL || methods_default_annotations->length() == methods->length(), ""); |
|
1375 assert(methods_type_annotations == NULL || methods_type_annotations->length() == methods->length(), ""); |
|
1376 if (do_annotations) { |
|
1377 ResourceMark rm; |
|
1378 // Allocate temporary storage |
|
1379 GrowableArray<AnnotationArray*>* temp_array = new GrowableArray<AnnotationArray*>(length); |
|
1380 reorder_based_on_method_index(methods, methods_annotations, temp_array); |
|
1381 reorder_based_on_method_index(methods, methods_parameter_annotations, temp_array); |
|
1382 reorder_based_on_method_index(methods, methods_default_annotations, temp_array); |
|
1383 reorder_based_on_method_index(methods, methods_type_annotations, temp_array); |
|
1384 } |
|
1385 |
|
1386 // Reset method ordering |
1322 // Reset method ordering |
1387 for (int i = 0; i < length; i++) { |
1323 for (int i = 0; i < length; i++) { |
1388 Method* m = methods->at(i); |
1324 Method* m = methods->at(i); |
1389 m->set_method_idnum(i); |
1325 m->set_method_idnum(i); |
1390 } |
1326 } |