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

Merge.
author Thomas Wuerthinger <wuerthinger@ssw.jku.at>
date Tue, 30 Nov 2010 14:53:30 +0100
parents 5571b97fc1ec d5d065957597
children 06f017f7daa7
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/_ciEnv.cpp.incl" 26 #include "incls/_ciEnv.cpp.incl"
510 // ------------------------------------------------------------------ 510 // ------------------------------------------------------------------
511 // ciEnv::get_constant_by_index_impl 511 // ciEnv::get_constant_by_index_impl
512 // 512 //
513 // Implementation of get_constant_by_index(). 513 // Implementation of get_constant_by_index().
514 ciConstant ciEnv::get_constant_by_index_impl(constantPoolHandle cpool, 514 ciConstant ciEnv::get_constant_by_index_impl(constantPoolHandle cpool,
515 int index, 515 int pool_index, int cache_index,
516 ciInstanceKlass* accessor) { 516 ciInstanceKlass* accessor) {
517 bool ignore_will_link;
517 EXCEPTION_CONTEXT; 518 EXCEPTION_CONTEXT;
519 int index = pool_index;
520 if (cache_index >= 0) {
521 assert(index < 0, "only one kind of index at a time");
522 ConstantPoolCacheEntry* cpc_entry = cpool->cache()->entry_at(cache_index);
523 index = cpc_entry->constant_pool_index();
524 oop obj = cpc_entry->f1();
525 if (obj != NULL) {
526 assert(obj->is_instance(), "must be an instance");
527 ciObject* ciobj = get_object(obj);
528 return ciConstant(T_OBJECT, ciobj);
529 }
530 }
518 constantTag tag = cpool->tag_at(index); 531 constantTag tag = cpool->tag_at(index);
519 if (tag.is_int()) { 532 if (tag.is_int()) {
520 return ciConstant(T_INT, (jint)cpool->int_at(index)); 533 return ciConstant(T_INT, (jint)cpool->int_at(index));
521 } else if (tag.is_long()) { 534 } else if (tag.is_long()) {
522 return ciConstant((jlong)cpool->long_at(index)); 535 return ciConstant((jlong)cpool->long_at(index));
539 ciObject* constant = get_object(string); 552 ciObject* constant = get_object(string);
540 assert (constant->is_instance(), "must be an instance, or not? "); 553 assert (constant->is_instance(), "must be an instance, or not? ");
541 return ciConstant(T_OBJECT, constant); 554 return ciConstant(T_OBJECT, constant);
542 } else if (tag.is_klass() || tag.is_unresolved_klass()) { 555 } else if (tag.is_klass() || tag.is_unresolved_klass()) {
543 // 4881222: allow ldc to take a class type 556 // 4881222: allow ldc to take a class type
544 bool ignore; 557 ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore_will_link, accessor);
545 ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore, accessor);
546 if (HAS_PENDING_EXCEPTION) { 558 if (HAS_PENDING_EXCEPTION) {
547 CLEAR_PENDING_EXCEPTION; 559 CLEAR_PENDING_EXCEPTION;
548 record_out_of_memory_failure(); 560 record_out_of_memory_failure();
549 return ciConstant(); 561 return ciConstant();
550 } 562 }
551 assert (klass->is_instance_klass() || klass->is_array_klass(), 563 assert (klass->is_instance_klass() || klass->is_array_klass(),
552 "must be an instance or array klass "); 564 "must be an instance or array klass ");
553 return ciConstant(T_OBJECT, klass); 565 return ciConstant(T_OBJECT, klass->java_mirror());
554 } else if (tag.is_object()) { 566 } else if (tag.is_object()) {
555 oop obj = cpool->object_at(index); 567 oop obj = cpool->object_at(index);
556 assert(obj->is_instance(), "must be an instance"); 568 assert(obj->is_instance(), "must be an instance");
557 ciObject* ciobj = get_object(obj); 569 ciObject* ciobj = get_object(obj);
558 return ciConstant(T_OBJECT, ciobj); 570 return ciConstant(T_OBJECT, ciobj);
571 } else if (tag.is_method_type()) {
572 // must execute Java code to link this CP entry into cache[i].f1
573 ciSymbol* signature = get_object(cpool->method_type_signature_at(index))->as_symbol();
574 ciObject* ciobj = get_unloaded_method_type_constant(signature);
575 return ciConstant(T_OBJECT, ciobj);
576 } else if (tag.is_method_handle()) {
577 // must execute Java code to link this CP entry into cache[i].f1
578 int ref_kind = cpool->method_handle_ref_kind_at(index);
579 int callee_index = cpool->method_handle_klass_index_at(index);
580 ciKlass* callee = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor);
581 ciSymbol* name = get_object(cpool->method_handle_name_ref_at(index))->as_symbol();
582 ciSymbol* signature = get_object(cpool->method_handle_signature_ref_at(index))->as_symbol();
583 ciObject* ciobj = get_unloaded_method_handle_constant(callee, name, signature, ref_kind);
584 return ciConstant(T_OBJECT, ciobj);
559 } else { 585 } else {
560 ShouldNotReachHere(); 586 ShouldNotReachHere();
561 return ciConstant(); 587 return ciConstant();
562 } 588 }
563 }
564
565 // ------------------------------------------------------------------
566 // ciEnv::is_unresolved_string_impl
567 //
568 // Implementation of is_unresolved_string().
569 bool ciEnv::is_unresolved_string_impl(instanceKlass* accessor, int index) const {
570 EXCEPTION_CONTEXT;
571 assert(accessor->is_linked(), "must be linked before accessing constant pool");
572 constantPoolOop cpool = accessor->constants();
573 constantTag tag = cpool->tag_at(index);
574 return tag.is_unresolved_string();
575 }
576
577 // ------------------------------------------------------------------
578 // ciEnv::is_unresolved_klass_impl
579 //
580 // Implementation of is_unresolved_klass().
581 bool ciEnv::is_unresolved_klass_impl(instanceKlass* accessor, int index) const {
582 EXCEPTION_CONTEXT;
583 assert(accessor->is_linked(), "must be linked before accessing constant pool");
584 constantPoolOop cpool = accessor->constants();
585 constantTag tag = cpool->tag_at(index);
586 return tag.is_unresolved_klass();
587 } 589 }
588 590
589 // ------------------------------------------------------------------ 591 // ------------------------------------------------------------------
590 // ciEnv::get_constant_by_index 592 // ciEnv::get_constant_by_index
591 // 593 //
592 // Pull a constant out of the constant pool. How appropriate. 594 // Pull a constant out of the constant pool. How appropriate.
593 // 595 //
594 // Implementation note: this query is currently in no way cached. 596 // Implementation note: this query is currently in no way cached.
595 ciConstant ciEnv::get_constant_by_index(constantPoolHandle cpool, 597 ciConstant ciEnv::get_constant_by_index(constantPoolHandle cpool,
596 int index, 598 int pool_index, int cache_index,
597 ciInstanceKlass* accessor) { 599 ciInstanceKlass* accessor) {
598 GUARDED_VM_ENTRY(return get_constant_by_index_impl(cpool, index, accessor);) 600 GUARDED_VM_ENTRY(return get_constant_by_index_impl(cpool, pool_index, cache_index, accessor);)
599 }
600
601 // ------------------------------------------------------------------
602 // ciEnv::is_unresolved_string
603 //
604 // Check constant pool
605 //
606 // Implementation note: this query is currently in no way cached.
607 bool ciEnv::is_unresolved_string(ciInstanceKlass* accessor,
608 int index) const {
609 GUARDED_VM_ENTRY(return is_unresolved_string_impl(accessor->get_instanceKlass(), index); )
610 }
611
612 // ------------------------------------------------------------------
613 // ciEnv::is_unresolved_klass
614 //
615 // Check constant pool
616 //
617 // Implementation note: this query is currently in no way cached.
618 bool ciEnv::is_unresolved_klass(ciInstanceKlass* accessor,
619 int index) const {
620 GUARDED_VM_ENTRY(return is_unresolved_klass_impl(accessor->get_instanceKlass(), index); )
621 } 601 }
622 602
623 // ------------------------------------------------------------------ 603 // ------------------------------------------------------------------
624 // ciEnv::get_field_by_index_impl 604 // ciEnv::get_field_by_index_impl
625 // 605 //
730 710
731 // ------------------------------------------------------------------ 711 // ------------------------------------------------------------------
732 // ciEnv::get_fake_invokedynamic_method_impl 712 // ciEnv::get_fake_invokedynamic_method_impl
733 ciMethod* ciEnv::get_fake_invokedynamic_method_impl(constantPoolHandle cpool, 713 ciMethod* ciEnv::get_fake_invokedynamic_method_impl(constantPoolHandle cpool,
734 int index, Bytecodes::Code bc) { 714 int index, Bytecodes::Code bc) {
715 // Compare the following logic with InterpreterRuntime::resolve_invokedynamic.
735 assert(bc == Bytecodes::_invokedynamic, "must be invokedynamic"); 716 assert(bc == Bytecodes::_invokedynamic, "must be invokedynamic");
736 717
737 // Get the CallSite from the constant pool cache. 718 bool is_resolved = cpool->cache()->main_entry_at(index)->is_resolved(bc);
738 ConstantPoolCacheEntry* cpc_entry = cpool->cache()->secondary_entry_at(index); 719 if (is_resolved && (oop) cpool->cache()->secondary_entry_at(index)->f1() == NULL)
739 assert(cpc_entry != NULL && cpc_entry->is_secondary_entry(), "sanity"); 720 // FIXME: code generation could allow for null (unlinked) call site
740 Handle call_site = cpc_entry->f1(); 721 is_resolved = false;
741 722
742 // Call site might not be linked yet. 723 // Call site might not be resolved yet. We could create a real invoker method from the
743 if (call_site.is_null()) { 724 // compiler, but it is simpler to stop the code path here with an unlinked method.
725 if (!is_resolved) {
744 ciInstanceKlass* mh_klass = get_object(SystemDictionary::MethodHandle_klass())->as_instance_klass(); 726 ciInstanceKlass* mh_klass = get_object(SystemDictionary::MethodHandle_klass())->as_instance_klass();
745 ciSymbol* sig_sym = get_object(cpool->signature_ref_at(index))->as_symbol(); 727 ciSymbol* sig_sym = get_object(cpool->signature_ref_at(index))->as_symbol();
746 return get_unloaded_method(mh_klass, ciSymbol::invoke_name(), sig_sym); 728 return get_unloaded_method(mh_klass, ciSymbol::invokeExact_name(), sig_sym);
747 } 729 }
748 730
749 // Get the methodOop from the CallSite. 731 // Get the invoker methodOop from the constant pool.
750 methodOop method_oop = (methodOop) java_dyn_CallSite::vmmethod(call_site()); 732 oop f1_value = cpool->cache()->main_entry_at(index)->f1();
751 assert(method_oop != NULL, "sanity"); 733 methodOop signature_invoker = methodOop(f1_value);
752 assert(method_oop->is_method_handle_invoke(), "consistent"); 734 assert(signature_invoker != NULL && signature_invoker->is_method() && signature_invoker->is_method_handle_invoke(),
753 735 "correct result from LinkResolver::resolve_invokedynamic");
754 return get_object(method_oop)->as_method(); 736
737 return get_object(signature_invoker)->as_method();
755 } 738 }
756 739
757 740
758 // ------------------------------------------------------------------ 741 // ------------------------------------------------------------------
759 // ciEnv::get_instance_klass_for_declared_method_holder 742 // ciEnv::get_instance_klass_for_declared_method_holder
972 // Record successful registration. 955 // Record successful registration.
973 // (Put nm into the task handle *before* publishing to the Java heap.) 956 // (Put nm into the task handle *before* publishing to the Java heap.)
974 if (task() != NULL) task()->set_code(nm); 957 if (task() != NULL) task()->set_code(nm);
975 958
976 if (entry_bci == InvocationEntryBci) { 959 if (entry_bci == InvocationEntryBci) {
977 #ifdef TIERED 960 if (TieredCompilation) {
978 // If there is an old version we're done with it 961 // If there is an old version we're done with it
979 nmethod* old = method->code(); 962 nmethod* old = method->code();
980 if (TraceMethodReplacement && old != NULL) { 963 if (TraceMethodReplacement && old != NULL) {
981 ResourceMark rm; 964 ResourceMark rm;
982 char *method_name = method->name_and_sig_as_C_string(); 965 char *method_name = method->name_and_sig_as_C_string();
983 tty->print_cr("Replacing method %s", method_name); 966 tty->print_cr("Replacing method %s", method_name);
967 }
968 if (old != NULL ) {
969 old->make_not_entrant();
970 }
984 } 971 }
985 if (old != NULL ) {
986 old->make_not_entrant();
987 }
988 #endif // TIERED
989 if (TraceNMethodInstalls ) { 972 if (TraceNMethodInstalls ) {
990 ResourceMark rm; 973 ResourceMark rm;
991 char *method_name = method->name_and_sig_as_C_string(); 974 char *method_name = method->name_and_sig_as_C_string();
992 ttyLocker ttyl; 975 ttyLocker ttyl;
993 tty->print_cr("Installing method (%d) %s ", 976 tty->print_cr("Installing method (%d) %s ",
1027 } 1010 }
1028 1011
1029 // ------------------------------------------------------------------ 1012 // ------------------------------------------------------------------
1030 // ciEnv::comp_level 1013 // ciEnv::comp_level
1031 int ciEnv::comp_level() { 1014 int ciEnv::comp_level() {
1032 if (task() == NULL) return CompLevel_full_optimization; 1015 if (task() == NULL) return CompLevel_highest_tier;
1033 return task()->comp_level(); 1016 return task()->comp_level();
1034 } 1017 }
1035 1018
1036 // ------------------------------------------------------------------ 1019 // ------------------------------------------------------------------
1037 // ciEnv::compile_id 1020 // ciEnv::compile_id