comparison src/share/vm/oops/method.cpp @ 8124:5fc51c1ecdeb

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 05 Mar 2013 23:44:54 +0100
parents 989155e2d07a 927a311d00f9
children b8f261ba79c6
comparison
equal deleted inserted replaced
7943:a413bcd552a4 8124:5fc51c1ecdeb
1 /* 1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
21 * questions. 21 * questions.
22 * 22 *
23 */ 23 */
24 24
25 #include "precompiled.hpp" 25 #include "precompiled.hpp"
26 #include "classfile/metadataOnStackMark.hpp"
26 #include "classfile/systemDictionary.hpp" 27 #include "classfile/systemDictionary.hpp"
27 #include "code/debugInfoRec.hpp" 28 #include "code/debugInfoRec.hpp"
28 #include "gc_interface/collectedHeap.inline.hpp" 29 #include "gc_interface/collectedHeap.inline.hpp"
29 #include "interpreter/bytecodeStream.hpp" 30 #include "interpreter/bytecodeStream.hpp"
30 #include "interpreter/bytecodeTracer.hpp" 31 #include "interpreter/bytecodeTracer.hpp"
31 #include "interpreter/bytecodes.hpp" 32 #include "interpreter/bytecodes.hpp"
32 #include "interpreter/interpreter.hpp" 33 #include "interpreter/interpreter.hpp"
33 #include "interpreter/oopMapCache.hpp" 34 #include "interpreter/oopMapCache.hpp"
34 #include "memory/gcLocker.hpp" 35 #include "memory/gcLocker.hpp"
35 #include "memory/generation.hpp" 36 #include "memory/generation.hpp"
37 #include "memory/heapInspection.hpp"
36 #include "memory/metadataFactory.hpp" 38 #include "memory/metadataFactory.hpp"
37 #include "memory/oopFactory.hpp" 39 #include "memory/oopFactory.hpp"
38 #include "oops/constMethod.hpp" 40 #include "oops/constMethod.hpp"
39 #include "oops/methodData.hpp" 41 #include "oops/methodData.hpp"
40 #include "oops/method.hpp" 42 #include "oops/method.hpp"
41 #include "oops/oop.inline.hpp" 43 #include "oops/oop.inline.hpp"
42 #include "oops/symbol.hpp" 44 #include "oops/symbol.hpp"
43 #include "prims/jvmtiExport.hpp" 45 #include "prims/jvmtiExport.hpp"
44 #include "prims/jvmtiRedefineClasses.hpp"
45 #include "prims/methodHandles.hpp" 46 #include "prims/methodHandles.hpp"
46 #include "prims/nativeLookup.hpp" 47 #include "prims/nativeLookup.hpp"
47 #include "runtime/arguments.hpp" 48 #include "runtime/arguments.hpp"
48 #include "runtime/compilationPolicy.hpp" 49 #include "runtime/compilationPolicy.hpp"
49 #include "runtime/frame.inline.hpp" 50 #include "runtime/frame.inline.hpp"
61 // Implementation of Method 62 // Implementation of Method
62 63
63 Method* Method::allocate(ClassLoaderData* loader_data, 64 Method* Method::allocate(ClassLoaderData* loader_data,
64 int byte_code_size, 65 int byte_code_size,
65 AccessFlags access_flags, 66 AccessFlags access_flags,
66 int compressed_line_number_size, 67 InlineTableSizes* sizes,
67 int localvariable_table_length,
68 int exception_table_length,
69 int checked_exceptions_length,
70 int method_parameters_length,
71 u2 generic_signature_index,
72 ConstMethod::MethodType method_type, 68 ConstMethod::MethodType method_type,
73 TRAPS) { 69 TRAPS) {
74 assert(!access_flags.is_native() || byte_code_size == 0, 70 assert(!access_flags.is_native() || byte_code_size == 0,
75 "native methods should not contain byte codes"); 71 "native methods should not contain byte codes");
76 ConstMethod* cm = ConstMethod::allocate(loader_data, 72 ConstMethod* cm = ConstMethod::allocate(loader_data,
77 byte_code_size, 73 byte_code_size,
78 compressed_line_number_size, 74 sizes,
79 localvariable_table_length,
80 exception_table_length,
81 checked_exceptions_length,
82 method_parameters_length,
83 generic_signature_index,
84 method_type, 75 method_type,
85 CHECK_NULL); 76 CHECK_NULL);
86 77
87 int size = Method::size(access_flags.is_native()); 78 int size = Method::size(access_flags.is_native());
88 79
322 InstanceKlass* ik = (InstanceKlass*) k; 313 InstanceKlass* ik = (InstanceKlass*) k;
323 return ik->name(); 314 return ik->name();
324 } 315 }
325 316
326 317
327 void Method::set_interpreter_kind() {
328 int kind = Interpreter::method_kind(this);
329 assert(kind != Interpreter::invalid,
330 "interpreter entry must be valid");
331 set_interpreter_kind(kind);
332 }
333
334
335 // Attempt to return method oop to original state. Clear any pointers 318 // Attempt to return method oop to original state. Clear any pointers
336 // (to objects outside the shared spaces). We won't be able to predict 319 // (to objects outside the shared spaces). We won't be able to predict
337 // where they should point in a new JVM. Further initialize some 320 // where they should point in a new JVM. Further initialize some
338 // entries now in order allow them to be write protected later. 321 // entries now in order allow them to be write protected later.
339 322
340 void Method::remove_unshareable_info() { 323 void Method::remove_unshareable_info() {
341 unlink_method(); 324 unlink_method();
342 set_interpreter_kind();
343 } 325 }
344 326
345 327
346 bool Method::was_executed_more_than(int n) { 328 bool Method::was_executed_more_than(int n) {
347 // Invocation counter is reset when the Method* is compiled. 329 // Invocation counter is reset when the Method* is compiled.
705 address* signature_handler = signature_handler_addr(); 687 address* signature_handler = signature_handler_addr();
706 *signature_handler = handler; 688 *signature_handler = handler;
707 } 689 }
708 690
709 691
710 void Method::print_made_not_compilable(int comp_level, bool is_osr, bool report) { 692 void Method::print_made_not_compilable(int comp_level, bool is_osr, bool report, const char* reason) {
711 if (PrintCompilation && report) { 693 if (PrintCompilation && report) {
712 ttyLocker ttyl; 694 ttyLocker ttyl;
713 tty->print("made not %scompilable on ", is_osr ? "OSR " : ""); 695 tty->print("made not %scompilable on ", is_osr ? "OSR " : "");
714 if (comp_level == CompLevel_all) { 696 if (comp_level == CompLevel_all) {
715 tty->print("all levels "); 697 tty->print("all levels ");
719 tty->print("%d ", i); 701 tty->print("%d ", i);
720 } 702 }
721 } 703 }
722 this->print_short_name(tty); 704 this->print_short_name(tty);
723 int size = this->code_size(); 705 int size = this->code_size();
724 if (size > 0) 706 if (size > 0) {
725 tty->print(" (%d bytes)", size); 707 tty->print(" (%d bytes)", size);
708 }
709 if (reason != NULL) {
710 tty->print(" %s", reason);
711 }
726 tty->cr(); 712 tty->cr();
727 } 713 }
728 if ((TraceDeoptimization || LogCompilation) && (xtty != NULL)) { 714 if ((TraceDeoptimization || LogCompilation) && (xtty != NULL)) {
729 ResourceMark rm; 715 ResourceMark rm;
730 ttyLocker ttyl; 716 ttyLocker ttyl;
731 xtty->begin_elem("make_not_%scompilable thread='" UINTX_FORMAT "'", 717 xtty->begin_elem("make_not_%scompilable thread='" UINTX_FORMAT "'",
732 is_osr ? "osr_" : "", os::current_thread_id()); 718 is_osr ? "osr_" : "", os::current_thread_id());
719 if (reason != NULL) {
720 xtty->print(" reason=\'%s\'", reason);
721 }
733 xtty->method(this); 722 xtty->method(this);
734 xtty->stamp(); 723 xtty->stamp();
735 xtty->end_elem(); 724 xtty->end_elem();
736 } 725 }
737 } 726 }
749 return is_not_c2_compilable(); 738 return is_not_c2_compilable();
750 return false; 739 return false;
751 } 740 }
752 741
753 // call this when compiler finds that this method is not compilable 742 // call this when compiler finds that this method is not compilable
754 void Method::set_not_compilable(int comp_level, bool report) { 743 void Method::set_not_compilable(int comp_level, bool report, const char* reason) {
755 print_made_not_compilable(comp_level, /*is_osr*/ false, report); 744 print_made_not_compilable(comp_level, /*is_osr*/ false, report, reason);
756 if (comp_level == CompLevel_all) { 745 if (comp_level == CompLevel_all) {
757 set_not_c1_compilable(); 746 set_not_c1_compilable();
758 set_not_c2_compilable(); 747 set_not_c2_compilable();
759 } else { 748 } else {
760 if (is_c1_compile(comp_level)) 749 if (is_c1_compile(comp_level))
775 if (is_c2_compile(comp_level)) 764 if (is_c2_compile(comp_level))
776 return is_not_c2_osr_compilable(); 765 return is_not_c2_osr_compilable();
777 return false; 766 return false;
778 } 767 }
779 768
780 void Method::set_not_osr_compilable(int comp_level, bool report) { 769 void Method::set_not_osr_compilable(int comp_level, bool report, const char* reason) {
781 print_made_not_compilable(comp_level, /*is_osr*/ true, report); 770 print_made_not_compilable(comp_level, /*is_osr*/ true, report, reason);
782 if (comp_level == CompLevel_all) { 771 if (comp_level == CompLevel_all) {
783 set_not_c1_osr_compilable(); 772 set_not_c1_osr_compilable();
784 set_not_c2_osr_compilable(); 773 set_not_c2_osr_compilable();
785 } else { 774 } else {
786 if (is_c1_compile(comp_level)) 775 if (is_c1_compile(comp_level))
1034 cp = constantPoolHandle(THREAD, cp_oop); 1023 cp = constantPoolHandle(THREAD, cp_oop);
1035 } 1024 }
1036 cp->set_pool_holder(InstanceKlass::cast(holder())); 1025 cp->set_pool_holder(InstanceKlass::cast(holder()));
1037 cp->symbol_at_put(_imcp_invoke_name, name); 1026 cp->symbol_at_put(_imcp_invoke_name, name);
1038 cp->symbol_at_put(_imcp_invoke_signature, signature); 1027 cp->symbol_at_put(_imcp_invoke_signature, signature);
1039 cp->set_preresolution(); 1028 cp->set_has_preresolution();
1040 1029
1041 // decide on access bits: public or not? 1030 // decide on access bits: public or not?
1042 int flags_bits = (JVM_ACC_NATIVE | JVM_ACC_SYNTHETIC | JVM_ACC_FINAL); 1031 int flags_bits = (JVM_ACC_NATIVE | JVM_ACC_SYNTHETIC | JVM_ACC_FINAL);
1043 bool must_be_static = MethodHandles::is_signature_polymorphic_static(iid); 1032 bool must_be_static = MethodHandles::is_signature_polymorphic_static(iid);
1044 if (must_be_static) flags_bits |= JVM_ACC_STATIC; 1033 if (must_be_static) flags_bits |= JVM_ACC_STATIC;
1045 assert((flags_bits & JVM_ACC_PUBLIC) == 0, "do not expose these methods"); 1034 assert((flags_bits & JVM_ACC_PUBLIC) == 0, "do not expose these methods");
1046 1035
1047 methodHandle m; 1036 methodHandle m;
1048 { 1037 {
1038 InlineTableSizes sizes;
1049 Method* m_oop = Method::allocate(loader_data, 0, 1039 Method* m_oop = Method::allocate(loader_data, 0,
1050 accessFlags_from(flags_bits), 1040 accessFlags_from(flags_bits), &sizes,
1051 0, 0, 0, 0, 0, 0,
1052 ConstMethod::NORMAL, CHECK_(empty)); 1041 ConstMethod::NORMAL, CHECK_(empty));
1053 m = methodHandle(THREAD, m_oop); 1042 m = methodHandle(THREAD, m_oop);
1054 } 1043 }
1055 m->set_constants(cp()); 1044 m->set_constants(cp());
1056 m->set_name_index(_imcp_invoke_name); 1045 m->set_name_index(_imcp_invoke_name);
1095 u_char* new_compressed_linenumber_table, int new_compressed_linenumber_size, TRAPS) { 1084 u_char* new_compressed_linenumber_table, int new_compressed_linenumber_size, TRAPS) {
1096 // Code below does not work for native methods - they should never get rewritten anyway 1085 // Code below does not work for native methods - they should never get rewritten anyway
1097 assert(!m->is_native(), "cannot rewrite native methods"); 1086 assert(!m->is_native(), "cannot rewrite native methods");
1098 // Allocate new Method* 1087 // Allocate new Method*
1099 AccessFlags flags = m->access_flags(); 1088 AccessFlags flags = m->access_flags();
1100 u2 generic_signature_index = m->generic_signature_index(); 1089
1101 int checked_exceptions_len = m->checked_exceptions_length(); 1090 ConstMethod* cm = m->constMethod();
1102 int localvariable_len = m->localvariable_table_length(); 1091 int checked_exceptions_len = cm->checked_exceptions_length();
1103 int exception_table_len = m->exception_table_length(); 1092 int localvariable_len = cm->localvariable_table_length();
1104 int method_parameters_len = m->method_parameters_length(); 1093 int exception_table_len = cm->exception_table_length();
1094 int method_parameters_len = cm->method_parameters_length();
1095 int method_annotations_len = cm->method_annotations_length();
1096 int parameter_annotations_len = cm->parameter_annotations_length();
1097 int type_annotations_len = cm->type_annotations_length();
1098 int default_annotations_len = cm->default_annotations_length();
1099
1100 InlineTableSizes sizes(
1101 localvariable_len,
1102 new_compressed_linenumber_size,
1103 exception_table_len,
1104 checked_exceptions_len,
1105 method_parameters_len,
1106 cm->generic_signature_index(),
1107 method_annotations_len,
1108 parameter_annotations_len,
1109 type_annotations_len,
1110 default_annotations_len,
1111 0);
1105 1112
1106 ClassLoaderData* loader_data = m->method_holder()->class_loader_data(); 1113 ClassLoaderData* loader_data = m->method_holder()->class_loader_data();
1107 Method* newm_oop = Method::allocate(loader_data, 1114 Method* newm_oop = Method::allocate(loader_data,
1108 new_code_length, 1115 new_code_length,
1109 flags, 1116 flags,
1110 new_compressed_linenumber_size, 1117 &sizes,
1111 localvariable_len,
1112 exception_table_len,
1113 checked_exceptions_len,
1114 method_parameters_len,
1115 generic_signature_index,
1116 m->method_type(), 1118 m->method_type(),
1117 CHECK_(methodHandle())); 1119 CHECK_(methodHandle()));
1118 methodHandle newm (THREAD, newm_oop); 1120 methodHandle newm (THREAD, newm_oop);
1119 int new_method_size = newm->method_size(); 1121 int new_method_size = newm->method_size();
1120 1122
1310 if (WizardMode) signature()->print_symbol_on(st); 1312 if (WizardMode) signature()->print_symbol_on(st);
1311 else if (MethodHandles::is_signature_polymorphic(intrinsic_id())) 1313 else if (MethodHandles::is_signature_polymorphic(intrinsic_id()))
1312 MethodHandles::print_as_basic_type_signature_on(st, signature(), true); 1314 MethodHandles::print_as_basic_type_signature_on(st, signature(), true);
1313 } 1315 }
1314 1316
1315 // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array
1316 static void reorder_based_on_method_index(Array<Method*>* methods,
1317 Array<AnnotationArray*>* annotations,
1318 GrowableArray<AnnotationArray*>* temp_array) {
1319 if (annotations == NULL) {
1320 return;
1321 }
1322
1323 int length = methods->length();
1324 int i;
1325 // Copy to temp array
1326 temp_array->clear();
1327 for (i = 0; i < length; i++) {
1328 temp_array->append(annotations->at(i));
1329 }
1330
1331 // Copy back using old method indices
1332 for (i = 0; i < length; i++) {
1333 Method* m = methods->at(i);
1334 annotations->at_put(i, temp_array->at(m->method_idnum()));
1335 }
1336 }
1337
1338 // Comparer for sorting an object array containing 1317 // Comparer for sorting an object array containing
1339 // Method*s. 1318 // Method*s.
1340 static int method_comparator(Method* a, Method* b) { 1319 static int method_comparator(Method* a, Method* b) {
1341 return a->name()->fast_compare(b->name()); 1320 return a->name()->fast_compare(b->name());
1342 } 1321 }
1343 1322
1344 // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array 1323 // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array
1345 void Method::sort_methods(Array<Method*>* methods, 1324 void Method::sort_methods(Array<Method*>* methods, bool idempotent) {
1346 Array<AnnotationArray*>* methods_annotations,
1347 Array<AnnotationArray*>* methods_parameter_annotations,
1348 Array<AnnotationArray*>* methods_default_annotations,
1349 Array<AnnotationArray*>* methods_type_annotations,
1350 bool idempotent) {
1351 int length = methods->length(); 1325 int length = methods->length();
1352 if (length > 1) { 1326 if (length > 1) {
1353 bool do_annotations = false;
1354 if (methods_annotations != NULL ||
1355 methods_parameter_annotations != NULL ||
1356 methods_default_annotations != NULL ||
1357 methods_type_annotations != NULL) {
1358 do_annotations = true;
1359 }
1360 if (do_annotations) {
1361 // Remember current method ordering so we can reorder annotations
1362 for (int i = 0; i < length; i++) {
1363 Method* m = methods->at(i);
1364 m->set_method_idnum(i);
1365 }
1366 }
1367 { 1327 {
1368 No_Safepoint_Verifier nsv; 1328 No_Safepoint_Verifier nsv;
1369 QuickSort::sort<Method*>(methods->data(), length, method_comparator, idempotent); 1329 QuickSort::sort<Method*>(methods->data(), length, method_comparator, idempotent);
1370 } 1330 }
1371
1372 // Sort annotations if necessary
1373 assert(methods_annotations == NULL || methods_annotations->length() == methods->length(), "");
1374 assert(methods_parameter_annotations == NULL || methods_parameter_annotations->length() == methods->length(), "");
1375 assert(methods_default_annotations == NULL || methods_default_annotations->length() == methods->length(), "");
1376 assert(methods_type_annotations == NULL || methods_type_annotations->length() == methods->length(), "");
1377 if (do_annotations) {
1378 ResourceMark rm;
1379 // Allocate temporary storage
1380 GrowableArray<AnnotationArray*>* temp_array = new GrowableArray<AnnotationArray*>(length);
1381 reorder_based_on_method_index(methods, methods_annotations, temp_array);
1382 reorder_based_on_method_index(methods, methods_parameter_annotations, temp_array);
1383 reorder_based_on_method_index(methods, methods_default_annotations, temp_array);
1384 reorder_based_on_method_index(methods, methods_type_annotations, temp_array);
1385 }
1386
1387 // Reset method ordering 1331 // Reset method ordering
1388 for (int i = 0; i < length; i++) { 1332 for (int i = 0; i < length; i++) {
1389 Method* m = methods->at(i); 1333 Method* m = methods->at(i);
1390 m->set_method_idnum(i); 1334 m->set_method_idnum(i);
1391 } 1335 }
1392 } 1336 }
1393 } 1337 }
1394 1338
1395 1339
1396 //----------------------------------------------------------------------------------- 1340 //-----------------------------------------------------------------------------------
1397 // Non-product code 1341 // Non-product code unless JVM/TI needs it
1398 1342
1399 #ifndef PRODUCT 1343 #if !defined(PRODUCT) || INCLUDE_JVMTI
1400 class SignatureTypePrinter : public SignatureTypeNames { 1344 class SignatureTypePrinter : public SignatureTypeNames {
1401 private: 1345 private:
1402 outputStream* _st; 1346 outputStream* _st;
1403 bool _use_separator; 1347 bool _use_separator;
1404 1348
1429 name()->print_symbol_on(st); 1373 name()->print_symbol_on(st);
1430 st->print("("); 1374 st->print("(");
1431 sig.print_parameters(); 1375 sig.print_parameters();
1432 st->print(")"); 1376 st->print(")");
1433 } 1377 }
1434 1378 #endif // !PRODUCT || INCLUDE_JVMTI
1435 1379
1380
1381 //-----------------------------------------------------------------------------------
1382 // Non-product code
1383
1384 #ifndef PRODUCT
1436 void Method::print_codes_on(outputStream* st) const { 1385 void Method::print_codes_on(outputStream* st) const {
1437 print_codes_on(0, code_size(), st); 1386 print_codes_on(0, code_size(), st);
1438 } 1387 }
1439 1388
1440 void Method::print_codes_on(int from, int to, outputStream* st) const { 1389 void Method::print_codes_on(int from, int to, outputStream* st) const {
1961 method_holder()->print_value_on(st); 1910 method_holder()->print_value_on(st);
1962 if (WizardMode) st->print("[%d,%d]", size_of_parameters(), max_locals()); 1911 if (WizardMode) st->print("[%d,%d]", size_of_parameters(), max_locals());
1963 if (WizardMode && code() != NULL) st->print(" ((nmethod*)%p)", code()); 1912 if (WizardMode && code() != NULL) st->print(" ((nmethod*)%p)", code());
1964 } 1913 }
1965 1914
1915 #if INCLUDE_SERVICES
1916 // Size Statistics
1917 void Method::collect_statistics(KlassSizeStats *sz) const {
1918 int mysize = sz->count(this);
1919 sz->_method_bytes += mysize;
1920 sz->_method_all_bytes += mysize;
1921 sz->_rw_bytes += mysize;
1922
1923 if (constMethod()) {
1924 constMethod()->collect_statistics(sz);
1925 }
1926 if (method_data()) {
1927 method_data()->collect_statistics(sz);
1928 }
1929 }
1930 #endif // INCLUDE_SERVICES
1966 1931
1967 // Verification 1932 // Verification
1968 1933
1969 void Method::verify_on(outputStream* st) { 1934 void Method::verify_on(outputStream* st) {
1970 guarantee(is_method(), "object must be method"); 1935 guarantee(is_method(), "object must be method");