duke@435: /* stefank@2534: * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "classfile/javaClasses.hpp" stefank@2314: #include "gc_implementation/shared/markSweep.inline.hpp" stefank@2314: #include "gc_interface/collectedHeap.inline.hpp" stefank@2314: #include "interpreter/interpreter.hpp" stefank@2314: #include "memory/gcLocker.hpp" stefank@2314: #include "memory/resourceArea.hpp" stefank@2314: #include "memory/universe.inline.hpp" stefank@2314: #include "oops/constMethodKlass.hpp" stefank@2314: #include "oops/klassOop.hpp" stefank@2314: #include "oops/methodDataOop.hpp" stefank@2314: #include "oops/methodKlass.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "oops/oop.inline2.hpp" coleenp@2497: #include "oops/symbol.hpp" stefank@2314: #include "runtime/handles.inline.hpp" duke@435: duke@435: klassOop methodKlass::create_klass(TRAPS) { duke@435: methodKlass o; duke@435: KlassHandle h_this_klass(THREAD, Universe::klassKlassObj()); duke@435: KlassHandle k = base_create_klass(h_this_klass, header_size(), o.vtbl_value(), CHECK_NULL); duke@435: // Make sure size calculation is right duke@435: assert(k()->size() == align_object_size(header_size()), "wrong size for object"); duke@435: java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror duke@435: return k(); duke@435: } duke@435: duke@435: duke@435: int methodKlass::oop_size(oop obj) const { duke@435: assert(obj->is_method(), "must be method oop"); duke@435: return methodOop(obj)->object_size(); duke@435: } duke@435: duke@435: duke@435: bool methodKlass::oop_is_parsable(oop obj) const { duke@435: assert(obj->is_method(), "must be method oop"); duke@435: return methodOop(obj)->object_is_parsable(); duke@435: } duke@435: duke@435: duke@435: methodOop methodKlass::allocate(constMethodHandle xconst, duke@435: AccessFlags access_flags, TRAPS) { duke@435: int size = methodOopDesc::object_size(access_flags.is_native()); duke@435: KlassHandle h_k(THREAD, as_klassOop()); duke@435: assert(xconst()->is_parsable(), "possible publication protocol violation"); duke@435: methodOop m = (methodOop)CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL); duke@435: assert(!m->is_parsable(), "not expecting parsability yet."); duke@435: duke@435: No_Safepoint_Verifier no_safepoint; // until m becomes parsable below duke@435: m->set_constMethod(xconst()); duke@435: m->set_access_flags(access_flags); duke@435: m->set_method_size(size); duke@435: m->set_name_index(0); duke@435: m->set_signature_index(0); duke@435: #ifdef CC_INTERP duke@435: m->set_result_index(T_VOID); duke@435: #endif duke@435: m->set_constants(NULL); duke@435: m->set_max_stack(0); duke@435: m->set_max_locals(0); jrose@1291: m->set_intrinsic_id(vmIntrinsics::_none); phh@3427: m->set_jfr_towrite(false); duke@435: m->set_method_data(NULL); duke@435: m->set_interpreter_throwout_count(0); duke@435: m->set_vtable_index(methodOopDesc::garbage_vtable_index); duke@435: duke@435: // Fix and bury in methodOop duke@435: m->set_interpreter_entry(NULL); // sets i2i entry and from_int duke@435: m->set_adapter_entry(NULL); duke@435: m->clear_code(); // from_c/from_i get set to c2i/i2i duke@435: duke@435: if (access_flags.is_native()) { duke@435: m->clear_native_function(); duke@435: m->set_signature_handler(NULL); duke@435: } duke@435: duke@435: NOT_PRODUCT(m->set_compiled_invocation_count(0);) duke@435: m->set_interpreter_invocation_count(0); duke@435: m->invocation_counter()->init(); duke@435: m->backedge_counter()->init(); duke@435: m->clear_number_of_breakpoints(); iveresov@2138: iveresov@2630: #ifdef TIERED iveresov@2630: m->set_rate(0); iveresov@2630: m->set_prev_event_count(0); iveresov@2630: m->set_prev_time(0); iveresov@2630: #endif iveresov@2630: duke@435: assert(m->is_parsable(), "must be parsable here."); duke@435: assert(m->size() == size, "wrong size for object"); duke@435: // We should not publish an uprasable object's reference duke@435: // into one that is parsable, since that presents problems duke@435: // for the concurrent parallel marking and precleaning phases duke@435: // of concurrent gc (CMS). duke@435: xconst->set_method(m); duke@435: return m; duke@435: } duke@435: duke@435: duke@435: void methodKlass::oop_follow_contents(oop obj) { duke@435: assert (obj->is_method(), "object must be method"); duke@435: methodOop m = methodOop(obj); duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::methodKlassObj never moves. duke@435: MarkSweep::mark_and_push(m->adr_constMethod()); duke@435: MarkSweep::mark_and_push(m->adr_constants()); duke@435: if (m->method_data() != NULL) { duke@435: MarkSweep::mark_and_push(m->adr_method_data()); duke@435: } duke@435: } duke@435: duke@435: #ifndef SERIALGC duke@435: void methodKlass::oop_follow_contents(ParCompactionManager* cm, duke@435: oop obj) { duke@435: assert (obj->is_method(), "object must be method"); duke@435: methodOop m = methodOop(obj); duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::methodKlassObj never moves. duke@435: PSParallelCompact::mark_and_push(cm, m->adr_constMethod()); duke@435: PSParallelCompact::mark_and_push(cm, m->adr_constants()); duke@435: #ifdef COMPILER2 duke@435: if (m->method_data() != NULL) { duke@435: PSParallelCompact::mark_and_push(cm, m->adr_method_data()); duke@435: } duke@435: #endif // COMPILER2 duke@435: } duke@435: #endif // SERIALGC duke@435: duke@435: int methodKlass::oop_oop_iterate(oop obj, OopClosure* blk) { duke@435: assert (obj->is_method(), "object must be method"); duke@435: methodOop m = methodOop(obj); duke@435: // Get size before changing pointers. duke@435: // Don't call size() or oop_size() since that is a virtual call. duke@435: int size = m->object_size(); duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::methodKlassObj never moves duke@435: blk->do_oop(m->adr_constMethod()); duke@435: blk->do_oop(m->adr_constants()); duke@435: if (m->method_data() != NULL) { duke@435: blk->do_oop(m->adr_method_data()); duke@435: } duke@435: return size; duke@435: } duke@435: duke@435: duke@435: int methodKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) { duke@435: assert (obj->is_method(), "object must be method"); duke@435: methodOop m = methodOop(obj); duke@435: // Get size before changing pointers. duke@435: // Don't call size() or oop_size() since that is a virtual call. duke@435: int size = m->object_size(); duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::methodKlassObj never moves. duke@435: oop* adr; duke@435: adr = m->adr_constMethod(); duke@435: if (mr.contains(adr)) blk->do_oop(adr); duke@435: adr = m->adr_constants(); duke@435: if (mr.contains(adr)) blk->do_oop(adr); duke@435: if (m->method_data() != NULL) { duke@435: adr = m->adr_method_data(); duke@435: if (mr.contains(adr)) blk->do_oop(adr); duke@435: } duke@435: return size; duke@435: } duke@435: duke@435: duke@435: int methodKlass::oop_adjust_pointers(oop obj) { duke@435: assert(obj->is_method(), "should be method"); duke@435: methodOop m = methodOop(obj); duke@435: // Get size before changing pointers. duke@435: // Don't call size() or oop_size() since that is a virtual call. duke@435: int size = m->object_size(); duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::methodKlassObj never moves. duke@435: MarkSweep::adjust_pointer(m->adr_constMethod()); duke@435: MarkSweep::adjust_pointer(m->adr_constants()); duke@435: if (m->method_data() != NULL) { duke@435: MarkSweep::adjust_pointer(m->adr_method_data()); duke@435: } duke@435: return size; duke@435: } duke@435: duke@435: #ifndef SERIALGC duke@435: void methodKlass::oop_push_contents(PSPromotionManager* pm, oop obj) { duke@435: assert(obj->is_method(), "should be method"); duke@435: } duke@435: duke@435: int methodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { duke@435: assert(obj->is_method(), "should be method"); duke@435: methodOop m = methodOop(obj); duke@435: PSParallelCompact::adjust_pointer(m->adr_constMethod()); duke@435: PSParallelCompact::adjust_pointer(m->adr_constants()); duke@435: #ifdef COMPILER2 duke@435: if (m->method_data() != NULL) { duke@435: PSParallelCompact::adjust_pointer(m->adr_method_data()); duke@435: } duke@435: #endif // COMPILER2 duke@435: return m->object_size(); duke@435: } duke@435: #endif // SERIALGC duke@435: duke@435: #ifndef PRODUCT duke@435: duke@435: // Printing duke@435: duke@435: void methodKlass::oop_print_on(oop obj, outputStream* st) { duke@435: ResourceMark rm; duke@435: assert(obj->is_method(), "must be method"); duke@435: Klass::oop_print_on(obj, st); duke@435: methodOop m = methodOop(obj); jrose@1862: // get the effect of PrintOopAddress, always, for methods: jrose@1928: st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)m); duke@435: st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr(); jrose@1862: st->print (" - constants: "INTPTR_FORMAT" ", (address)m->constants()); duke@435: m->constants()->print_value_on(st); st->cr(); duke@435: st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr(); duke@435: st->print (" - name: "); m->name()->print_value_on(st); st->cr(); duke@435: st->print (" - signature: "); m->signature()->print_value_on(st); st->cr(); duke@435: st->print_cr(" - max stack: %d", m->max_stack()); duke@435: st->print_cr(" - max locals: %d", m->max_locals()); duke@435: st->print_cr(" - size of params: %d", m->size_of_parameters()); duke@435: st->print_cr(" - method size: %d", m->method_size()); jrose@1862: if (m->intrinsic_id() != vmIntrinsics::_none) jrose@1862: st->print_cr(" - intrinsic id: %d %s", m->intrinsic_id(), vmIntrinsics::name_at(m->intrinsic_id())); iveresov@2138: if (m->highest_comp_level() != CompLevel_none) iveresov@2138: st->print_cr(" - highest level: %d", m->highest_comp_level()); duke@435: st->print_cr(" - vtable index: %d", m->_vtable_index); jrose@1100: st->print_cr(" - i2i entry: " INTPTR_FORMAT, m->interpreter_entry()); jrose@1100: st->print_cr(" - adapter: " INTPTR_FORMAT, m->adapter()); jrose@1100: st->print_cr(" - compiled entry " INTPTR_FORMAT, m->from_compiled_entry()); duke@435: st->print_cr(" - code size: %d", m->code_size()); jrose@1100: if (m->code_size() != 0) { jrose@1100: st->print_cr(" - code start: " INTPTR_FORMAT, m->code_base()); jrose@1100: st->print_cr(" - code end (excl): " INTPTR_FORMAT, m->code_base() + m->code_size()); jrose@1100: } duke@435: if (m->method_data() != NULL) { duke@435: st->print_cr(" - method data: " INTPTR_FORMAT, (address)m->method_data()); duke@435: } duke@435: st->print_cr(" - checked ex length: %d", m->checked_exceptions_length()); duke@435: if (m->checked_exceptions_length() > 0) { duke@435: CheckedExceptionElement* table = m->checked_exceptions_start(); duke@435: st->print_cr(" - checked ex start: " INTPTR_FORMAT, table); duke@435: if (Verbose) { duke@435: for (int i = 0; i < m->checked_exceptions_length(); i++) { duke@435: st->print_cr(" - throws %s", m->constants()->printable_name_at(table[i].class_cp_index)); duke@435: } duke@435: } duke@435: } duke@435: if (m->has_linenumber_table()) { duke@435: u_char* table = m->compressed_linenumber_table(); duke@435: st->print_cr(" - linenumber start: " INTPTR_FORMAT, table); duke@435: if (Verbose) { duke@435: CompressedLineNumberReadStream stream(table); duke@435: while (stream.read_pair()) { duke@435: st->print_cr(" - line %d: %d", stream.line(), stream.bci()); duke@435: } duke@435: } duke@435: } duke@435: st->print_cr(" - localvar length: %d", m->localvariable_table_length()); duke@435: if (m->localvariable_table_length() > 0) { duke@435: LocalVariableTableElement* table = m->localvariable_table_start(); duke@435: st->print_cr(" - localvar start: " INTPTR_FORMAT, table); duke@435: if (Verbose) { duke@435: for (int i = 0; i < m->localvariable_table_length(); i++) { duke@435: int bci = table[i].start_bci; duke@435: int len = table[i].length; duke@435: const char* name = m->constants()->printable_name_at(table[i].name_cp_index); duke@435: const char* desc = m->constants()->printable_name_at(table[i].descriptor_cp_index); duke@435: int slot = table[i].slot; duke@435: st->print_cr(" - %s %s bci=%d len=%d slot=%d", desc, name, bci, len, slot); duke@435: } duke@435: } duke@435: } duke@435: if (m->code() != NULL) { duke@435: st->print (" - compiled code: "); duke@435: m->code()->print_value_on(st); duke@435: st->cr(); duke@435: } jrose@1145: if (m->is_method_handle_invoke()) { jrose@1145: st->print_cr(" - invoke method type: " INTPTR_FORMAT, (address) m->method_handle_type()); jrose@1145: // m is classified as native, but it does not have an interesting jrose@1145: // native_function or signature handler jrose@1145: } else if (m->is_native()) { jrose@1100: st->print_cr(" - native function: " INTPTR_FORMAT, m->native_function()); jrose@1100: st->print_cr(" - signature handler: " INTPTR_FORMAT, m->signature_handler()); jrose@1100: } duke@435: } duke@435: jrose@1590: #endif //PRODUCT duke@435: duke@435: void methodKlass::oop_print_value_on(oop obj, outputStream* st) { duke@435: assert(obj->is_method(), "must be method"); duke@435: Klass::oop_print_value_on(obj, st); duke@435: methodOop m = methodOop(obj); duke@435: st->print(" "); duke@435: m->name()->print_value_on(st); duke@435: st->print(" "); duke@435: m->signature()->print_value_on(st); duke@435: st->print(" in "); duke@435: m->method_holder()->print_value_on(st); duke@435: if (WizardMode) st->print("[%d,%d]", m->size_of_parameters(), m->max_locals()); duke@435: if (WizardMode && m->code() != NULL) st->print(" ((nmethod*)%p)", m->code()); duke@435: } duke@435: duke@435: const char* methodKlass::internal_name() const { duke@435: return "{method}"; duke@435: } duke@435: duke@435: duke@435: // Verification duke@435: duke@435: void methodKlass::oop_verify_on(oop obj, outputStream* st) { duke@435: Klass::oop_verify_on(obj, st); duke@435: guarantee(obj->is_method(), "object must be method"); duke@435: if (!obj->partially_loaded()) { duke@435: methodOop m = methodOop(obj); duke@435: guarantee(m->is_perm(), "should be in permspace"); duke@435: guarantee(m->constants()->is_perm(), "should be in permspace"); duke@435: guarantee(m->constants()->is_constantPool(), "should be constant pool"); duke@435: guarantee(m->constMethod()->is_constMethod(), "should be constMethodOop"); duke@435: guarantee(m->constMethod()->is_perm(), "should be in permspace"); duke@435: methodDataOop method_data = m->method_data(); duke@435: guarantee(method_data == NULL || duke@435: method_data->is_perm(), "should be in permspace"); duke@435: guarantee(method_data == NULL || duke@435: method_data->is_methodData(), "should be method data"); duke@435: } duke@435: } duke@435: duke@435: bool methodKlass::oop_partially_loaded(oop obj) const { duke@435: assert(obj->is_method(), "object must be method"); duke@435: methodOop m = methodOop(obj); duke@435: constMethodOop xconst = m->constMethod(); duke@435: assert(xconst != NULL, "const method must be set"); duke@435: constMethodKlass* ck = constMethodKlass::cast(xconst->klass()); duke@435: return ck->oop_partially_loaded(xconst); duke@435: } duke@435: duke@435: duke@435: void methodKlass::oop_set_partially_loaded(oop obj) { duke@435: assert(obj->is_method(), "object must be method"); duke@435: methodOop m = methodOop(obj); duke@435: constMethodOop xconst = m->constMethod(); duke@435: assert(xconst != NULL, "const method must be set"); duke@435: constMethodKlass* ck = constMethodKlass::cast(xconst->klass()); duke@435: ck->oop_set_partially_loaded(xconst); duke@435: }