comparison src/share/vm/ci/ciMethod.cpp @ 1930:2d26b0046e0d

Merge.
author Thomas Wuerthinger <wuerthinger@ssw.jku.at>
date Tue, 30 Nov 2010 14:53:30 +0100
parents 3f9a70eb8b1f
children f95d63e2154a
comparison
equal deleted inserted replaced
1484:6b7001391c97 1930:2d26b0046e0d
1 /* 1 /*
2 * Copyright 1999-2010 Sun Microsystems, Inc. All Rights Reserved. 2 * Copyright (c) 1999, 2010, 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.
14 * 14 *
15 * You should have received a copy of the GNU General Public License version 15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation, 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 * 18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * CA 95054 USA or visit www.sun.com if you need additional information or 20 * or visit www.oracle.com if you need additional information or have any
21 * have any questions. 21 * questions.
22 * 22 *
23 */ 23 */
24 24
25 #include "incls/_precompiled.incl" 25 #include "incls/_precompiled.incl"
26 #include "incls/_ciMethod.cpp.incl" 26 #include "incls/_ciMethod.cpp.incl"
47 _code_size = h_m()->code_size(); 47 _code_size = h_m()->code_size();
48 _intrinsic_id = h_m()->intrinsic_id(); 48 _intrinsic_id = h_m()->intrinsic_id();
49 _handler_count = h_m()->exception_table()->length() / 4; 49 _handler_count = h_m()->exception_table()->length() / 4;
50 _uses_monitors = h_m()->access_flags().has_monitor_bytecodes(); 50 _uses_monitors = h_m()->access_flags().has_monitor_bytecodes();
51 _balanced_monitors = !_uses_monitors || h_m()->access_flags().is_monitor_matching(); 51 _balanced_monitors = !_uses_monitors || h_m()->access_flags().is_monitor_matching();
52 _is_compilable = !h_m()->is_not_compilable(); 52 _is_c1_compilable = !h_m()->is_not_c1_compilable();
53 _is_c2_compilable = !h_m()->is_not_c2_compilable();
53 // Lazy fields, filled in on demand. Require allocation. 54 // Lazy fields, filled in on demand. Require allocation.
54 _code = NULL; 55 _code = NULL;
55 _exception_handlers = NULL; 56 _exception_handlers = NULL;
56 _liveness = NULL; 57 _liveness = NULL;
57 _bcea = NULL;
58 _method_blocks = NULL; 58 _method_blocks = NULL;
59 #ifdef COMPILER2 59 #if defined(COMPILER2) || defined(SHARK)
60 _flow = NULL; 60 _flow = NULL;
61 #endif // COMPILER2 61 _bcea = NULL;
62 #endif // COMPILER2 || SHARK
62 63
63 ciEnv *env = CURRENT_ENV; 64 ciEnv *env = CURRENT_ENV;
64 if (env->jvmti_can_hotswap_or_post_breakpoint() && _is_compilable) { 65 if (env->jvmti_can_hotswap_or_post_breakpoint() && can_be_compiled()) {
65 // 6328518 check hotswap conditions under the right lock. 66 // 6328518 check hotswap conditions under the right lock.
66 MutexLocker locker(Compile_lock); 67 MutexLocker locker(Compile_lock);
67 if (Dependencies::check_evol_method(h_m()) != NULL) { 68 if (Dependencies::check_evol_method(h_m()) != NULL) {
68 _is_compilable = false; 69 _is_c1_compilable = false;
70 _is_c2_compilable = false;
69 } 71 }
70 } else { 72 } else {
71 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); 73 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
72 } 74 }
73 75
91 _holder = env->get_object(h_m()->method_holder())->as_instance_klass(); 93 _holder = env->get_object(h_m()->method_holder())->as_instance_klass();
92 ciSymbol* sig_symbol = env->get_object(h_m()->signature())->as_symbol(); 94 ciSymbol* sig_symbol = env->get_object(h_m()->signature())->as_symbol();
93 _signature = new (env->arena()) ciSignature(_holder, sig_symbol); 95 _signature = new (env->arena()) ciSignature(_holder, sig_symbol);
94 _method_data = NULL; 96 _method_data = NULL;
95 // Take a snapshot of these values, so they will be commensurate with the MDO. 97 // Take a snapshot of these values, so they will be commensurate with the MDO.
96 if (ProfileInterpreter) { 98 if (ProfileInterpreter || TieredCompilation) {
97 int invcnt = h_m()->interpreter_invocation_count(); 99 int invcnt = h_m()->interpreter_invocation_count();
98 // if the value overflowed report it as max int 100 // if the value overflowed report it as max int
99 _interpreter_invocation_count = invcnt < 0 ? max_jint : invcnt ; 101 _interpreter_invocation_count = invcnt < 0 ? max_jint : invcnt ;
100 _interpreter_throwout_count = h_m()->interpreter_throwout_count(); 102 _interpreter_throwout_count = h_m()->interpreter_throwout_count();
101 } else { 103 } else {
119 _holder = holder; 121 _holder = holder;
120 _signature = new (CURRENT_ENV->arena()) ciSignature(_holder, signature); 122 _signature = new (CURRENT_ENV->arena()) ciSignature(_holder, signature);
121 _intrinsic_id = vmIntrinsics::_none; 123 _intrinsic_id = vmIntrinsics::_none;
122 _liveness = NULL; 124 _liveness = NULL;
123 _can_be_statically_bound = false; 125 _can_be_statically_bound = false;
124 _bcea = NULL;
125 _method_blocks = NULL; 126 _method_blocks = NULL;
126 _method_data = NULL; 127 _method_data = NULL;
127 #ifdef COMPILER2 128 #if defined(COMPILER2) || defined(SHARK)
128 _flow = NULL; 129 _flow = NULL;
129 #endif // COMPILER2 130 _bcea = NULL;
131 #endif // COMPILER2 || SHARK
130 } 132 }
131 133
132 134
133 // ------------------------------------------------------------------ 135 // ------------------------------------------------------------------
134 // ciMethod::load_code 136 // ciMethod::load_code
227 VM_ENTRY_MARK; 229 VM_ENTRY_MARK;
228 return get_methodOop()->vtable_index(); 230 return get_methodOop()->vtable_index();
229 } 231 }
230 232
231 233
234 #ifdef SHARK
235 // ------------------------------------------------------------------
236 // ciMethod::itable_index
237 //
238 // Get the position of this method's entry in the itable, if any.
239 int ciMethod::itable_index() {
240 check_is_loaded();
241 assert(holder()->is_linked(), "must be linked");
242 VM_ENTRY_MARK;
243 return klassItable::compute_itable_index(get_methodOop());
244 }
245 #endif // SHARK
246
247
232 // ------------------------------------------------------------------ 248 // ------------------------------------------------------------------
233 // ciMethod::native_entry 249 // ciMethod::native_entry
234 // 250 //
235 // Get the address of this method's native code, if any. 251 // Get the address of this method's native code, if any.
236 address ciMethod::native_entry() { 252 address ciMethod::native_entry() {
292 308
293 309
294 // ------------------------------------------------------------------ 310 // ------------------------------------------------------------------
295 // ciMethod::get_flow_analysis 311 // ciMethod::get_flow_analysis
296 ciTypeFlow* ciMethod::get_flow_analysis() { 312 ciTypeFlow* ciMethod::get_flow_analysis() {
297 #ifdef COMPILER2 313 #if defined(COMPILER2) || defined(SHARK)
298 if (_flow == NULL) { 314 if (_flow == NULL) {
299 ciEnv* env = CURRENT_ENV; 315 ciEnv* env = CURRENT_ENV;
300 _flow = new (env->arena()) ciTypeFlow(env, this); 316 _flow = new (env->arena()) ciTypeFlow(env, this);
301 _flow->do_flow(); 317 _flow->do_flow();
302 } 318 }
303 return _flow; 319 return _flow;
304 #else // COMPILER2 320 #else // COMPILER2 || SHARK
305 ShouldNotReachHere(); 321 ShouldNotReachHere();
306 return NULL; 322 return NULL;
307 #endif // COMPILER2 323 #endif // COMPILER2 || SHARK
308 } 324 }
309 325
310 326
311 // ------------------------------------------------------------------ 327 // ------------------------------------------------------------------
312 // ciMethod::get_osr_flow_analysis 328 // ciMethod::get_osr_flow_analysis
313 ciTypeFlow* ciMethod::get_osr_flow_analysis(int osr_bci) { 329 ciTypeFlow* ciMethod::get_osr_flow_analysis(int osr_bci) {
314 #ifdef COMPILER2 330 #if defined(COMPILER2) || defined(SHARK)
315 // OSR entry points are always place after a call bytecode of some sort 331 // OSR entry points are always place after a call bytecode of some sort
316 assert(osr_bci >= 0, "must supply valid OSR entry point"); 332 assert(osr_bci >= 0, "must supply valid OSR entry point");
317 ciEnv* env = CURRENT_ENV; 333 ciEnv* env = CURRENT_ENV;
318 ciTypeFlow* flow = new (env->arena()) ciTypeFlow(env, this, osr_bci); 334 ciTypeFlow* flow = new (env->arena()) ciTypeFlow(env, this, osr_bci);
319 flow->do_flow(); 335 flow->do_flow();
320 return flow; 336 return flow;
321 #else // COMPILER2 337 #else // COMPILER2 || SHARK
322 ShouldNotReachHere(); 338 ShouldNotReachHere();
323 return NULL; 339 return NULL;
324 #endif // COMPILER2 340 #endif // COMPILER2 || SHARK
325 } 341 }
326 342
327 // ------------------------------------------------------------------ 343 // ------------------------------------------------------------------
328 // ciMethod::raw_liveness_at_bci 344 // ciMethod::raw_liveness_at_bci
329 // 345 //
421 } else { // ReceiverTypeData is a subclass of CounterData 437 } else { // ReceiverTypeData is a subclass of CounterData
422 ciReceiverTypeData* call = (ciReceiverTypeData*)data->as_ReceiverTypeData(); 438 ciReceiverTypeData* call = (ciReceiverTypeData*)data->as_ReceiverTypeData();
423 // In addition, virtual call sites have receiver type information 439 // In addition, virtual call sites have receiver type information
424 int receivers_count_total = 0; 440 int receivers_count_total = 0;
425 int morphism = 0; 441 int morphism = 0;
442 // Precompute morphism for the possible fixup
426 for (uint i = 0; i < call->row_limit(); i++) { 443 for (uint i = 0; i < call->row_limit(); i++) {
427 ciKlass* receiver = call->receiver(i); 444 ciKlass* receiver = call->receiver(i);
428 if (receiver == NULL) continue; 445 if (receiver == NULL) continue;
429 morphism += 1; 446 morphism++;
430 int rcount = call->receiver_count(i); 447 }
448 int epsilon = 0;
449 if (TieredCompilation && ProfileInterpreter) {
450 // Interpreter and C1 treat final and special invokes differently.
451 // C1 will record a type, whereas the interpreter will just
452 // increment the count. Detect this case.
453 if (morphism == 1 && count > 0) {
454 epsilon = count;
455 count = 0;
456 }
457 }
458 for (uint i = 0; i < call->row_limit(); i++) {
459 ciKlass* receiver = call->receiver(i);
460 if (receiver == NULL) continue;
461 int rcount = call->receiver_count(i) + epsilon;
431 if (rcount == 0) rcount = 1; // Should be valid value 462 if (rcount == 0) rcount = 1; // Should be valid value
432 receivers_count_total += rcount; 463 receivers_count_total += rcount;
433 // Add the receiver to result data. 464 // Add the receiver to result data.
434 result.add_receiver(receiver, rcount); 465 result.add_receiver(receiver, rcount);
435 // If we extend profiling to record methods, 466 // If we extend profiling to record methods,
671 // counts in the MDO should be scaled by 4X, so that 702 // counts in the MDO should be scaled by 4X, so that
672 // they can be usefully and stably compared against the 703 // they can be usefully and stably compared against the
673 // invocation counts in methods. 704 // invocation counts in methods.
674 int ciMethod::scale_count(int count, float prof_factor) { 705 int ciMethod::scale_count(int count, float prof_factor) {
675 if (count > 0 && method_data() != NULL) { 706 if (count > 0 && method_data() != NULL) {
676 int current_mileage = method_data()->current_mileage(); 707 int counter_life;
677 int creation_mileage = method_data()->creation_mileage();
678 int counter_life = current_mileage - creation_mileage;
679 int method_life = interpreter_invocation_count(); 708 int method_life = interpreter_invocation_count();
709 if (TieredCompilation) {
710 // In tiered the MDO's life is measured directly, so just use the snapshotted counters
711 counter_life = MAX2(method_data()->invocation_count(), method_data()->backedge_count());
712 } else {
713 int current_mileage = method_data()->current_mileage();
714 int creation_mileage = method_data()->creation_mileage();
715 counter_life = current_mileage - creation_mileage;
716 }
717
680 // counter_life due to backedge_counter could be > method_life 718 // counter_life due to backedge_counter could be > method_life
681 if (counter_life > method_life) 719 if (counter_life > method_life)
682 counter_life = method_life; 720 counter_life = method_life;
683 if (0 < counter_life && counter_life <= method_life) { 721 if (0 < counter_life && counter_life <= method_life) {
684 count = (int)((double)count * prof_factor * method_life / counter_life + 0.5); 722 count = (int)((double)count * prof_factor * method_life / counter_life + 0.5);
688 return count; 726 return count;
689 } 727 }
690 728
691 // ------------------------------------------------------------------ 729 // ------------------------------------------------------------------
692 // invokedynamic support 730 // invokedynamic support
693 // 731
732 // ------------------------------------------------------------------
733 // ciMethod::is_method_handle_invoke
734 //
735 // Return true if the method is an instance of one of the two
736 // signature-polymorphic MethodHandle methods, invokeExact or invokeGeneric.
694 bool ciMethod::is_method_handle_invoke() const { 737 bool ciMethod::is_method_handle_invoke() const {
695 check_is_loaded(); 738 if (!is_loaded()) {
696 bool flag = ((flags().as_int() & JVM_MH_INVOKE_BITS) == JVM_MH_INVOKE_BITS); 739 bool flag = (holder()->name() == ciSymbol::java_dyn_MethodHandle() &&
697 #ifdef ASSERT 740 methodOopDesc::is_method_handle_invoke_name(name()->sid()));
698 { 741 return flag;
699 VM_ENTRY_MARK; 742 }
700 bool flag2 = get_methodOop()->is_method_handle_invoke(); 743 VM_ENTRY_MARK;
701 assert(flag == flag2, "consistent"); 744 return get_methodOop()->is_method_handle_invoke();
702 } 745 }
703 #endif //ASSERT 746
704 return flag; 747 // ------------------------------------------------------------------
705 } 748 // ciMethod::is_method_handle_adapter
706 749 //
750 // Return true if the method is a generated MethodHandle adapter.
751 // These are built by MethodHandleCompiler.
707 bool ciMethod::is_method_handle_adapter() const { 752 bool ciMethod::is_method_handle_adapter() const {
708 check_is_loaded(); 753 if (!is_loaded()) return false;
709 VM_ENTRY_MARK; 754 VM_ENTRY_MARK;
710 return get_methodOop()->is_method_handle_adapter(); 755 return get_methodOop()->is_method_handle_adapter();
711 } 756 }
712 757
713 ciInstance* ciMethod::method_handle_type() { 758 ciInstance* ciMethod::method_handle_type() {
759 VM_ENTRY_MARK; 804 VM_ENTRY_MARK;
760 ciEnv* env = CURRENT_ENV; 805 ciEnv* env = CURRENT_ENV;
761 Thread* my_thread = JavaThread::current(); 806 Thread* my_thread = JavaThread::current();
762 methodHandle h_m(my_thread, get_methodOop()); 807 methodHandle h_m(my_thread, get_methodOop());
763 808
764 if (Tier1UpdateMethodData && is_tier1_compile(env->comp_level())) { 809 // Create an MDO for the inlinee
810 if (TieredCompilation && is_c1_compile(env->comp_level())) {
765 build_method_data(h_m); 811 build_method_data(h_m);
766 } 812 }
767 813
768 if (h_m()->method_data() != NULL) { 814 if (h_m()->method_data() != NULL) {
769 _method_data = CURRENT_ENV->get_object(h_m()->method_data())->as_method_data(); 815 _method_data = CURRENT_ENV->get_object(h_m()->method_data())->as_method_data();
866 // ciMethod::can_be_compiled 912 // ciMethod::can_be_compiled
867 // 913 //
868 // Have previous compilations of this method succeeded? 914 // Have previous compilations of this method succeeded?
869 bool ciMethod::can_be_compiled() { 915 bool ciMethod::can_be_compiled() {
870 check_is_loaded(); 916 check_is_loaded();
871 return _is_compilable; 917 ciEnv* env = CURRENT_ENV;
918 if (is_c1_compile(env->comp_level())) {
919 return _is_c1_compilable;
920 }
921 return _is_c2_compilable;
872 } 922 }
873 923
874 // ------------------------------------------------------------------ 924 // ------------------------------------------------------------------
875 // ciMethod::set_not_compilable 925 // ciMethod::set_not_compilable
876 // 926 //
877 // Tell the VM that this method cannot be compiled at all. 927 // Tell the VM that this method cannot be compiled at all.
878 void ciMethod::set_not_compilable() { 928 void ciMethod::set_not_compilable() {
879 check_is_loaded(); 929 check_is_loaded();
880 VM_ENTRY_MARK; 930 VM_ENTRY_MARK;
881 _is_compilable = false; 931 ciEnv* env = CURRENT_ENV;
882 get_methodOop()->set_not_compilable(); 932 if (is_c1_compile(env->comp_level())) {
933 _is_c1_compilable = false;
934 } else {
935 _is_c2_compilable = false;
936 }
937 get_methodOop()->set_not_compilable(env->comp_level());
883 } 938 }
884 939
885 // ------------------------------------------------------------------ 940 // ------------------------------------------------------------------
886 // ciMethod::can_be_osr_compiled 941 // ciMethod::can_be_osr_compiled
887 // 942 //
891 // of failed OSR compilations per bci. The entry_bci parameter 946 // of failed OSR compilations per bci. The entry_bci parameter
892 // is currently unused. 947 // is currently unused.
893 bool ciMethod::can_be_osr_compiled(int entry_bci) { 948 bool ciMethod::can_be_osr_compiled(int entry_bci) {
894 check_is_loaded(); 949 check_is_loaded();
895 VM_ENTRY_MARK; 950 VM_ENTRY_MARK;
896 return !get_methodOop()->access_flags().is_not_osr_compilable(); 951 ciEnv* env = CURRENT_ENV;
952 return !get_methodOop()->is_not_osr_compilable(env->comp_level());
897 } 953 }
898 954
899 // ------------------------------------------------------------------ 955 // ------------------------------------------------------------------
900 // ciMethod::has_compiled_code 956 // ciMethod::has_compiled_code
901 bool ciMethod::has_compiled_code() { 957 bool ciMethod::has_compiled_code() {
902 VM_ENTRY_MARK; 958 VM_ENTRY_MARK;
903 return get_methodOop()->code() != NULL; 959 return get_methodOop()->code() != NULL;
904 } 960 }
905 961
962 int ciMethod::comp_level() {
963 check_is_loaded();
964 VM_ENTRY_MARK;
965 nmethod* nm = get_methodOop()->code();
966 if (nm != NULL) return nm->comp_level();
967 return 0;
968 }
969
906 // ------------------------------------------------------------------ 970 // ------------------------------------------------------------------
907 // ciMethod::instructions_size 971 // ciMethod::instructions_size
908 // This is a rough metric for "fat" methods, compared 972 //
909 // before inlining with InlineSmallCode. 973 // This is a rough metric for "fat" methods, compared before inlining
910 // The CodeBlob::instructions_size accessor includes 974 // with InlineSmallCode. The CodeBlob::code_size accessor includes
911 // junk like exception handler, stubs, and constant table, 975 // junk like exception handler, stubs, and constant table, which are
912 // which are not highly relevant to an inlined method. 976 // not highly relevant to an inlined method. So we use the more
913 // So we use the more specific accessor nmethod::code_size. 977 // specific accessor nmethod::insts_size.
914 int ciMethod::instructions_size() { 978 int ciMethod::instructions_size(int comp_level) {
915 GUARDED_VM_ENTRY( 979 GUARDED_VM_ENTRY(
916 nmethod* code = get_methodOop()->code(); 980 nmethod* code = get_methodOop()->code();
917 // if there's no compiled code or the code was produced by the 981 if (code != NULL && (comp_level == CompLevel_any || comp_level == code->comp_level())) {
918 // tier1 profiler return 0 for the code size. This should 982 return code->insts_end() - code->verified_entry_point();
919 // probably be based on the compilation level of the nmethod but 983 }
920 // that currently isn't properly recorded. 984 return 0;
921 if (code == NULL ||
922 (TieredCompilation && code->compiler() != NULL && code->compiler()->is_c1())) {
923 return 0;
924 }
925 return code->code_end() - code->verified_entry_point();
926 ) 985 )
927 } 986 }
928 987
929 // ------------------------------------------------------------------ 988 // ------------------------------------------------------------------
930 // ciMethod::log_nmethod_identity 989 // ciMethod::log_nmethod_identity
1019 bool ciMethod::has_jsrs () const { FETCH_FLAG_FROM_VM(has_jsrs); } 1078 bool ciMethod::has_jsrs () const { FETCH_FLAG_FROM_VM(has_jsrs); }
1020 bool ciMethod::is_accessor () const { FETCH_FLAG_FROM_VM(is_accessor); } 1079 bool ciMethod::is_accessor () const { FETCH_FLAG_FROM_VM(is_accessor); }
1021 bool ciMethod::is_initializer () const { FETCH_FLAG_FROM_VM(is_initializer); } 1080 bool ciMethod::is_initializer () const { FETCH_FLAG_FROM_VM(is_initializer); }
1022 1081
1023 BCEscapeAnalyzer *ciMethod::get_bcea() { 1082 BCEscapeAnalyzer *ciMethod::get_bcea() {
1083 #ifdef COMPILER2
1024 if (_bcea == NULL) { 1084 if (_bcea == NULL) {
1025 _bcea = new (CURRENT_ENV->arena()) BCEscapeAnalyzer(this, NULL); 1085 _bcea = new (CURRENT_ENV->arena()) BCEscapeAnalyzer(this, NULL);
1026 } 1086 }
1027 return _bcea; 1087 return _bcea;
1088 #else // COMPILER2
1089 ShouldNotReachHere();
1090 return NULL;
1091 #endif // COMPILER2
1028 } 1092 }
1029 1093
1030 ciMethodBlocks *ciMethod::get_method_blocks() { 1094 ciMethodBlocks *ciMethod::get_method_blocks() {
1031 Arena *arena = CURRENT_ENV->arena(); 1095 Arena *arena = CURRENT_ENV->arena();
1032 if (_method_blocks == NULL) { 1096 if (_method_blocks == NULL) {