comparison src/share/vm/ci/ciEnv.cpp @ 1339:09ac706c2623

Merge
author asaha
date Wed, 24 Mar 2010 17:16:33 -0700
parents f5dd08ad65df 7f8790caccb0
children b4776199210f
comparison
equal deleted inserted replaced
1338:f5dd08ad65df 1339:09ac706c2623
1 /* 1 /*
2 * Copyright 1999-2009 Sun Microsystems, Inc. All Rights Reserved. 2 * Copyright 1999-2010 Sun Microsystems, Inc. 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.
36 ciKlassKlass* ciEnv::_klass_klass_instance; 36 ciKlassKlass* ciEnv::_klass_klass_instance;
37 ciInstanceKlassKlass* ciEnv::_instance_klass_klass_instance; 37 ciInstanceKlassKlass* ciEnv::_instance_klass_klass_instance;
38 ciTypeArrayKlassKlass* ciEnv::_type_array_klass_klass_instance; 38 ciTypeArrayKlassKlass* ciEnv::_type_array_klass_klass_instance;
39 ciObjArrayKlassKlass* ciEnv::_obj_array_klass_klass_instance; 39 ciObjArrayKlassKlass* ciEnv::_obj_array_klass_klass_instance;
40 40
41 ciInstanceKlass* ciEnv::_ArrayStoreException; 41 #define WK_KLASS_DEFN(name, ignore_s, ignore_o) ciInstanceKlass* ciEnv::_##name = NULL;
42 ciInstanceKlass* ciEnv::_Class; 42 WK_KLASSES_DO(WK_KLASS_DEFN)
43 ciInstanceKlass* ciEnv::_ClassCastException; 43 #undef WK_KLASS_DEFN
44 ciInstanceKlass* ciEnv::_Object;
45 ciInstanceKlass* ciEnv::_Throwable;
46 ciInstanceKlass* ciEnv::_Thread;
47 ciInstanceKlass* ciEnv::_OutOfMemoryError;
48 ciInstanceKlass* ciEnv::_String;
49 44
50 ciSymbol* ciEnv::_unloaded_cisymbol = NULL; 45 ciSymbol* ciEnv::_unloaded_cisymbol = NULL;
51 ciInstanceKlass* ciEnv::_unloaded_ciinstance_klass = NULL; 46 ciInstanceKlass* ciEnv::_unloaded_ciinstance_klass = NULL;
52 ciObjArrayKlass* ciEnv::_unloaded_ciobjarrayklass = NULL; 47 ciObjArrayKlass* ciEnv::_unloaded_ciobjarrayklass = NULL;
53 48
108 _ArithmeticException_instance = get_object(o)->as_instance(); 103 _ArithmeticException_instance = get_object(o)->as_instance();
109 104
110 _ArrayIndexOutOfBoundsException_instance = NULL; 105 _ArrayIndexOutOfBoundsException_instance = NULL;
111 _ArrayStoreException_instance = NULL; 106 _ArrayStoreException_instance = NULL;
112 _ClassCastException_instance = NULL; 107 _ClassCastException_instance = NULL;
108 _the_null_string = NULL;
109 _the_min_jint_string = NULL;
113 } 110 }
114 111
115 ciEnv::ciEnv(Arena* arena) { 112 ciEnv::ciEnv(Arena* arena) {
116 ASSERT_IN_VM; 113 ASSERT_IN_VM;
117 114
161 _ArithmeticException_instance = get_object(o)->as_instance(); 158 _ArithmeticException_instance = get_object(o)->as_instance();
162 159
163 _ArrayIndexOutOfBoundsException_instance = NULL; 160 _ArrayIndexOutOfBoundsException_instance = NULL;
164 _ArrayStoreException_instance = NULL; 161 _ArrayStoreException_instance = NULL;
165 _ClassCastException_instance = NULL; 162 _ClassCastException_instance = NULL;
163 _the_null_string = NULL;
164 _the_min_jint_string = NULL;
166 } 165 }
167 166
168 ciEnv::~ciEnv() { 167 ciEnv::~ciEnv() {
169 CompilerThread* current_thread = CompilerThread::current(); 168 CompilerThread* current_thread = CompilerThread::current();
170 current_thread->set_env(NULL); 169 current_thread->set_env(NULL);
177 // Get Jvmti capabilities under lock to get consistant values. 176 // Get Jvmti capabilities under lock to get consistant values.
178 MutexLocker mu(JvmtiThreadState_lock); 177 MutexLocker mu(JvmtiThreadState_lock);
179 _jvmti_can_hotswap_or_post_breakpoint = JvmtiExport::can_hotswap_or_post_breakpoint(); 178 _jvmti_can_hotswap_or_post_breakpoint = JvmtiExport::can_hotswap_or_post_breakpoint();
180 _jvmti_can_examine_or_deopt_anywhere = JvmtiExport::can_examine_or_deopt_anywhere(); 179 _jvmti_can_examine_or_deopt_anywhere = JvmtiExport::can_examine_or_deopt_anywhere();
181 _jvmti_can_access_local_variables = JvmtiExport::can_access_local_variables(); 180 _jvmti_can_access_local_variables = JvmtiExport::can_access_local_variables();
182 _jvmti_can_post_exceptions = JvmtiExport::can_post_exceptions(); 181 _jvmti_can_post_on_exceptions = JvmtiExport::can_post_on_exceptions();
183 } 182 }
184 183
185 // ------------------------------------------------------------------ 184 // ------------------------------------------------------------------
186 // Cache DTrace flags 185 // Cache DTrace flags
187 void ciEnv::cache_dtrace_flags() { 186 void ciEnv::cache_dtrace_flags() {
244 _ClassCastException_instance 243 _ClassCastException_instance
245 = get_or_create_exception(_ClassCastException_handle, 244 = get_or_create_exception(_ClassCastException_handle,
246 vmSymbolHandles::java_lang_ClassCastException()); 245 vmSymbolHandles::java_lang_ClassCastException());
247 } 246 }
248 return _ClassCastException_instance; 247 return _ClassCastException_instance;
248 }
249
250 ciInstance* ciEnv::the_null_string() {
251 if (_the_null_string == NULL) {
252 VM_ENTRY_MARK;
253 _the_null_string = get_object(Universe::the_null_string())->as_instance();
254 }
255 return _the_null_string;
256 }
257
258 ciInstance* ciEnv::the_min_jint_string() {
259 if (_the_min_jint_string == NULL) {
260 VM_ENTRY_MARK;
261 _the_min_jint_string = get_object(Universe::the_min_jint_string())->as_instance();
262 }
263 return _the_min_jint_string;
249 } 264 }
250 265
251 // ------------------------------------------------------------------ 266 // ------------------------------------------------------------------
252 // ciEnv::get_method_from_handle 267 // ciEnv::get_method_from_handle
253 ciMethod* ciEnv::get_method_from_handle(jobject method) { 268 ciMethod* ciEnv::get_method_from_handle(jobject method) {
417 432
418 // ------------------------------------------------------------------ 433 // ------------------------------------------------------------------
419 // ciEnv::get_klass_by_index_impl 434 // ciEnv::get_klass_by_index_impl
420 // 435 //
421 // Implementation of get_klass_by_index. 436 // Implementation of get_klass_by_index.
422 ciKlass* ciEnv::get_klass_by_index_impl(ciInstanceKlass* accessor, 437 ciKlass* ciEnv::get_klass_by_index_impl(constantPoolHandle cpool,
423 int index, 438 int index,
424 bool& is_accessible) { 439 bool& is_accessible,
425 assert(accessor->get_instanceKlass()->is_linked(), "must be linked before accessing constant pool"); 440 ciInstanceKlass* accessor) {
426 EXCEPTION_CONTEXT; 441 EXCEPTION_CONTEXT;
427 constantPoolHandle cpool(THREAD, accessor->get_instanceKlass()->constants());
428 KlassHandle klass (THREAD, constantPoolOopDesc::klass_at_if_loaded(cpool, index)); 442 KlassHandle klass (THREAD, constantPoolOopDesc::klass_at_if_loaded(cpool, index));
429 symbolHandle klass_name; 443 symbolHandle klass_name;
430 if (klass.is_null()) { 444 if (klass.is_null()) {
431 // The klass has not been inserted into the constant pool. 445 // The klass has not been inserted into the constant pool.
432 // Try to look it up by name. 446 // Try to look it up by name.
484 498
485 // ------------------------------------------------------------------ 499 // ------------------------------------------------------------------
486 // ciEnv::get_klass_by_index 500 // ciEnv::get_klass_by_index
487 // 501 //
488 // Get a klass from the constant pool. 502 // Get a klass from the constant pool.
489 ciKlass* ciEnv::get_klass_by_index(ciInstanceKlass* accessor, 503 ciKlass* ciEnv::get_klass_by_index(constantPoolHandle cpool,
490 int index, 504 int index,
491 bool& is_accessible) { 505 bool& is_accessible,
492 GUARDED_VM_ENTRY(return get_klass_by_index_impl(accessor, index, is_accessible);) 506 ciInstanceKlass* accessor) {
507 GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);)
493 } 508 }
494 509
495 // ------------------------------------------------------------------ 510 // ------------------------------------------------------------------
496 // ciEnv::get_constant_by_index_impl 511 // ciEnv::get_constant_by_index_impl
497 // 512 //
498 // Implementation of get_constant_by_index(). 513 // Implementation of get_constant_by_index().
499 ciConstant ciEnv::get_constant_by_index_impl(ciInstanceKlass* accessor, 514 ciConstant ciEnv::get_constant_by_index_impl(constantPoolHandle cpool,
500 int index) { 515 int index,
516 ciInstanceKlass* accessor) {
501 EXCEPTION_CONTEXT; 517 EXCEPTION_CONTEXT;
502 instanceKlass* ik_accessor = accessor->get_instanceKlass();
503 assert(ik_accessor->is_linked(), "must be linked before accessing constant pool");
504 constantPoolOop cpool = ik_accessor->constants();
505 constantTag tag = cpool->tag_at(index); 518 constantTag tag = cpool->tag_at(index);
506 if (tag.is_int()) { 519 if (tag.is_int()) {
507 return ciConstant(T_INT, (jint)cpool->int_at(index)); 520 return ciConstant(T_INT, (jint)cpool->int_at(index));
508 } else if (tag.is_long()) { 521 } else if (tag.is_long()) {
509 return ciConstant((jlong)cpool->long_at(index)); 522 return ciConstant((jlong)cpool->long_at(index));
527 assert (constant->is_instance(), "must be an instance, or not? "); 540 assert (constant->is_instance(), "must be an instance, or not? ");
528 return ciConstant(T_OBJECT, constant); 541 return ciConstant(T_OBJECT, constant);
529 } else if (tag.is_klass() || tag.is_unresolved_klass()) { 542 } else if (tag.is_klass() || tag.is_unresolved_klass()) {
530 // 4881222: allow ldc to take a class type 543 // 4881222: allow ldc to take a class type
531 bool ignore; 544 bool ignore;
532 ciKlass* klass = get_klass_by_index_impl(accessor, index, ignore); 545 ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore, accessor);
533 if (HAS_PENDING_EXCEPTION) { 546 if (HAS_PENDING_EXCEPTION) {
534 CLEAR_PENDING_EXCEPTION; 547 CLEAR_PENDING_EXCEPTION;
535 record_out_of_memory_failure(); 548 record_out_of_memory_failure();
536 return ciConstant(); 549 return ciConstant();
537 } 550 }
538 assert (klass->is_instance_klass() || klass->is_array_klass(), 551 assert (klass->is_instance_klass() || klass->is_array_klass(),
539 "must be an instance or array klass "); 552 "must be an instance or array klass ");
540 return ciConstant(T_OBJECT, klass); 553 return ciConstant(T_OBJECT, klass);
554 } else if (tag.is_object()) {
555 oop obj = cpool->object_at(index);
556 assert(obj->is_instance(), "must be an instance");
557 ciObject* ciobj = get_object(obj);
558 return ciConstant(T_OBJECT, ciobj);
541 } else { 559 } else {
542 ShouldNotReachHere(); 560 ShouldNotReachHere();
543 return ciConstant(); 561 return ciConstant();
544 } 562 }
545 } 563 }
572 // ciEnv::get_constant_by_index 590 // ciEnv::get_constant_by_index
573 // 591 //
574 // Pull a constant out of the constant pool. How appropriate. 592 // Pull a constant out of the constant pool. How appropriate.
575 // 593 //
576 // Implementation note: this query is currently in no way cached. 594 // Implementation note: this query is currently in no way cached.
577 ciConstant ciEnv::get_constant_by_index(ciInstanceKlass* accessor, 595 ciConstant ciEnv::get_constant_by_index(constantPoolHandle cpool,
578 int index) { 596 int index,
579 GUARDED_VM_ENTRY(return get_constant_by_index_impl(accessor, index); ) 597 ciInstanceKlass* accessor) {
598 GUARDED_VM_ENTRY(return get_constant_by_index_impl(cpool, index, accessor);)
580 } 599 }
581 600
582 // ------------------------------------------------------------------ 601 // ------------------------------------------------------------------
583 // ciEnv::is_unresolved_string 602 // ciEnv::is_unresolved_string
584 // 603 //
585 // Check constant pool 604 // Check constant pool
586 // 605 //
587 // Implementation note: this query is currently in no way cached. 606 // Implementation note: this query is currently in no way cached.
588 bool ciEnv::is_unresolved_string(ciInstanceKlass* accessor, 607 bool ciEnv::is_unresolved_string(ciInstanceKlass* accessor,
589 int index) const { 608 int index) const {
590 GUARDED_VM_ENTRY(return is_unresolved_string_impl(accessor->get_instanceKlass(), index); ) 609 GUARDED_VM_ENTRY(return is_unresolved_string_impl(accessor->get_instanceKlass(), index); )
591 } 610 }
592 611
593 // ------------------------------------------------------------------ 612 // ------------------------------------------------------------------
594 // ciEnv::is_unresolved_klass 613 // ciEnv::is_unresolved_klass
595 // 614 //
596 // Check constant pool 615 // Check constant pool
597 // 616 //
598 // Implementation note: this query is currently in no way cached. 617 // Implementation note: this query is currently in no way cached.
599 bool ciEnv::is_unresolved_klass(ciInstanceKlass* accessor, 618 bool ciEnv::is_unresolved_klass(ciInstanceKlass* accessor,
600 int index) const { 619 int index) const {
601 GUARDED_VM_ENTRY(return is_unresolved_klass_impl(accessor->get_instanceKlass(), index); ) 620 GUARDED_VM_ENTRY(return is_unresolved_klass_impl(accessor->get_instanceKlass(), index); )
602 } 621 }
603 622
604 // ------------------------------------------------------------------ 623 // ------------------------------------------------------------------
605 // ciEnv::get_field_by_index_impl 624 // ciEnv::get_field_by_index_impl
676 } 695 }
677 696
678 697
679 // ------------------------------------------------------------------ 698 // ------------------------------------------------------------------
680 // ciEnv::get_method_by_index_impl 699 // ciEnv::get_method_by_index_impl
681 ciMethod* ciEnv::get_method_by_index_impl(ciInstanceKlass* accessor, 700 ciMethod* ciEnv::get_method_by_index_impl(constantPoolHandle cpool,
682 int index, Bytecodes::Code bc) { 701 int index, Bytecodes::Code bc,
683 // Get the method's declared holder. 702 ciInstanceKlass* accessor) {
684
685 assert(accessor->get_instanceKlass()->is_linked(), "must be linked before accessing constant pool");
686 constantPoolHandle cpool = accessor->get_instanceKlass()->constants();
687 int holder_index = cpool->klass_ref_index_at(index); 703 int holder_index = cpool->klass_ref_index_at(index);
688 bool holder_is_accessible; 704 bool holder_is_accessible;
689 ciKlass* holder = get_klass_by_index_impl(accessor, holder_index, holder_is_accessible); 705 ciKlass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor);
690 ciInstanceKlass* declared_holder = get_instance_klass_for_declared_method_holder(holder); 706 ciInstanceKlass* declared_holder = get_instance_klass_for_declared_method_holder(holder);
691 707
692 // Get the method's name and signature. 708 // Get the method's name and signature.
693 int nt_index = cpool->name_and_type_ref_index_at(index);
694 int sig_index = cpool->signature_ref_index_at(nt_index);
695 symbolOop name_sym = cpool->name_ref_at(index); 709 symbolOop name_sym = cpool->name_ref_at(index);
696 symbolOop sig_sym = cpool->symbol_at(sig_index); 710 symbolOop sig_sym = cpool->signature_ref_at(index);
697 711
698 if (holder_is_accessible) { // Our declared holder is loaded. 712 if (holder_is_accessible) { // Our declared holder is loaded.
699 instanceKlass* lookup = declared_holder->get_instanceKlass(); 713 instanceKlass* lookup = declared_holder->get_instanceKlass();
700 methodOop m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc); 714 methodOop m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc);
701 if (m != NULL) { 715 if (m != NULL) {
709 // lookup. 723 // lookup.
710 724
711 return get_unloaded_method(declared_holder, 725 return get_unloaded_method(declared_holder,
712 get_object(name_sym)->as_symbol(), 726 get_object(name_sym)->as_symbol(),
713 get_object(sig_sym)->as_symbol()); 727 get_object(sig_sym)->as_symbol());
728 }
729
730
731 // ------------------------------------------------------------------
732 // ciEnv::get_fake_invokedynamic_method_impl
733 ciMethod* ciEnv::get_fake_invokedynamic_method_impl(constantPoolHandle cpool,
734 int index, Bytecodes::Code bc) {
735 assert(bc == Bytecodes::_invokedynamic, "must be invokedynamic");
736
737 // Get the CallSite from the constant pool cache.
738 ConstantPoolCacheEntry* cpc_entry = cpool->cache()->secondary_entry_at(index);
739 assert(cpc_entry != NULL && cpc_entry->is_secondary_entry(), "sanity");
740 Handle call_site = cpc_entry->f1();
741
742 // Call site might not be linked yet.
743 if (call_site.is_null()) {
744 ciInstanceKlass* mh_klass = get_object(SystemDictionary::MethodHandle_klass())->as_instance_klass();
745 ciSymbol* sig_sym = get_object(cpool->signature_ref_at(index))->as_symbol();
746 return get_unloaded_method(mh_klass, ciSymbol::invoke_name(), sig_sym);
747 }
748
749 // Get the methodOop from the CallSite.
750 methodOop method_oop = (methodOop) java_dyn_CallSite::vmmethod(call_site());
751 assert(method_oop != NULL, "sanity");
752 assert(method_oop->is_method_handle_invoke(), "consistent");
753
754 return get_object(method_oop)->as_method();
714 } 755 }
715 756
716 757
717 // ------------------------------------------------------------------ 758 // ------------------------------------------------------------------
718 // ciEnv::get_instance_klass_for_declared_method_holder 759 // ciEnv::get_instance_klass_for_declared_method_holder
734 } 775 }
735 return NULL; 776 return NULL;
736 } 777 }
737 778
738 779
739
740
741 // ------------------------------------------------------------------ 780 // ------------------------------------------------------------------
742 // ciEnv::get_method_by_index 781 // ciEnv::get_method_by_index
743 ciMethod* ciEnv::get_method_by_index(ciInstanceKlass* accessor, 782 ciMethod* ciEnv::get_method_by_index(constantPoolHandle cpool,
744 int index, Bytecodes::Code bc) { 783 int index, Bytecodes::Code bc,
745 GUARDED_VM_ENTRY(return get_method_by_index_impl(accessor, index, bc);) 784 ciInstanceKlass* accessor) {
746 } 785 if (bc == Bytecodes::_invokedynamic) {
786 GUARDED_VM_ENTRY(return get_fake_invokedynamic_method_impl(cpool, index, bc);)
787 } else {
788 GUARDED_VM_ENTRY(return get_method_by_index_impl(cpool, index, bc, accessor);)
789 }
790 }
791
747 792
748 // ------------------------------------------------------------------ 793 // ------------------------------------------------------------------
749 // ciEnv::name_buffer 794 // ciEnv::name_buffer
750 char *ciEnv::name_buffer(int req_len) { 795 char *ciEnv::name_buffer(int req_len) {
751 if (_name_buffer_len < req_len) { 796 if (_name_buffer_len < req_len) {
844 JvmtiExport::can_hotswap_or_post_breakpoint()) || 889 JvmtiExport::can_hotswap_or_post_breakpoint()) ||
845 (!jvmti_can_examine_or_deopt_anywhere() && 890 (!jvmti_can_examine_or_deopt_anywhere() &&
846 JvmtiExport::can_examine_or_deopt_anywhere()) || 891 JvmtiExport::can_examine_or_deopt_anywhere()) ||
847 (!jvmti_can_access_local_variables() && 892 (!jvmti_can_access_local_variables() &&
848 JvmtiExport::can_access_local_variables()) || 893 JvmtiExport::can_access_local_variables()) ||
849 (!jvmti_can_post_exceptions() && 894 (!jvmti_can_post_on_exceptions() &&
850 JvmtiExport::can_post_exceptions()) )) { 895 JvmtiExport::can_post_on_exceptions()) )) {
851 record_failure("Jvmti state change invalidated dependencies"); 896 record_failure("Jvmti state change invalidated dependencies");
852 } 897 }
853 898
854 // Change in DTrace flags may invalidate compilation. 899 // Change in DTrace flags may invalidate compilation.
855 if (!failing() && 900 if (!failing() &&
915 } 960 }
916 961
917 if (nm == NULL) { 962 if (nm == NULL) {
918 // The CodeCache is full. Print out warning and disable compilation. 963 // The CodeCache is full. Print out warning and disable compilation.
919 record_failure("code cache is full"); 964 record_failure("code cache is full");
920 UseInterpreter = true; 965 {
921 if (UseCompiler || AlwaysCompileLoopMethods ) { 966 MutexUnlocker ml(Compile_lock);
922 #ifndef PRODUCT 967 MutexUnlocker locker(MethodCompileQueue_lock);
923 warning("CodeCache is full. Compiler has been disabled"); 968 CompileBroker::handle_full_code_cache();
924 if (CompileTheWorld || ExitOnFullCodeCache) {
925 before_exit(JavaThread::current());
926 exit_globals(); // will delete tty
927 vm_direct_exit(CompileTheWorld ? 0 : 1);
928 }
929 #endif
930 UseCompiler = false;
931 AlwaysCompileLoopMethods = false;
932 } 969 }
933 } else { 970 } else {
934 NOT_PRODUCT(nm->set_has_debug_info(has_debug_info); ) 971 NOT_PRODUCT(nm->set_has_debug_info(has_debug_info); )
935 nm->set_has_unsafe_access(has_unsafe_access); 972 nm->set_has_unsafe_access(has_unsafe_access);
936 973