duke@435: /* stefank@2314: * Copyright (c) 2003, 2010, 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 "gc_implementation/shared/markSweep.inline.hpp" stefank@2314: #include "interpreter/interpreter.hpp" stefank@2314: #include "memory/gcLocker.hpp" stefank@2314: #include "memory/resourceArea.hpp" stefank@2314: #include "oops/constMethodKlass.hpp" stefank@2314: #include "oops/constMethodOop.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "oops/oop.inline2.hpp" stefank@2314: #include "runtime/handles.inline.hpp" duke@435: duke@435: duke@435: klassOop constMethodKlass::create_klass(TRAPS) { duke@435: constMethodKlass o; duke@435: KlassHandle h_this_klass(THREAD, Universe::klassKlassObj()); duke@435: KlassHandle k = base_create_klass(h_this_klass, header_size(), duke@435: o.vtbl_value(), CHECK_NULL); duke@435: // Make sure size calculation is right duke@435: assert(k()->size() == align_object_size(header_size()), duke@435: "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 constMethodKlass::oop_size(oop obj) const { duke@435: assert(obj->is_constMethod(), "must be constMethod oop"); duke@435: return constMethodOop(obj)->object_size(); duke@435: } duke@435: duke@435: bool constMethodKlass::oop_is_parsable(oop obj) const { duke@435: assert(obj->is_constMethod(), "must be constMethod oop"); duke@435: return constMethodOop(obj)->object_is_parsable(); duke@435: } duke@435: jmasa@953: bool constMethodKlass::oop_is_conc_safe(oop obj) const { jmasa@953: assert(obj->is_constMethod(), "must be constMethod oop"); jmasa@953: return constMethodOop(obj)->is_conc_safe(); jmasa@953: } jmasa@953: duke@435: constMethodOop constMethodKlass::allocate(int byte_code_size, duke@435: int compressed_line_number_size, duke@435: int localvariable_table_length, duke@435: int checked_exceptions_length, jmasa@953: bool is_conc_safe, duke@435: TRAPS) { duke@435: duke@435: int size = constMethodOopDesc::object_size(byte_code_size, duke@435: compressed_line_number_size, duke@435: localvariable_table_length, duke@435: checked_exceptions_length); duke@435: KlassHandle h_k(THREAD, as_klassOop()); duke@435: constMethodOop cm = (constMethodOop) duke@435: CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL); duke@435: assert(!cm->is_parsable(), "Not yet safely parsable"); duke@435: No_Safepoint_Verifier no_safepoint; duke@435: cm->set_interpreter_kind(Interpreter::invalid); duke@435: cm->init_fingerprint(); duke@435: cm->set_method(NULL); duke@435: cm->set_stackmap_data(NULL); duke@435: cm->set_exception_table(NULL); duke@435: cm->set_code_size(byte_code_size); duke@435: cm->set_constMethod_size(size); duke@435: cm->set_inlined_tables_length(checked_exceptions_length, duke@435: compressed_line_number_size, duke@435: localvariable_table_length); duke@435: assert(cm->size() == size, "wrong size for object"); jmasa@953: cm->set_is_conc_safe(is_conc_safe); duke@435: cm->set_partially_loaded(); duke@435: assert(cm->is_parsable(), "Is safely parsable by gc"); duke@435: return cm; duke@435: } duke@435: duke@435: void constMethodKlass::oop_follow_contents(oop obj) { duke@435: assert (obj->is_constMethod(), "object must be constMethod"); duke@435: constMethodOop cm = constMethodOop(obj); duke@435: MarkSweep::mark_and_push(cm->adr_method()); duke@435: MarkSweep::mark_and_push(cm->adr_stackmap_data()); duke@435: MarkSweep::mark_and_push(cm->adr_exception_table()); duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::constMethodKlassObj never moves. duke@435: } duke@435: duke@435: #ifndef SERIALGC duke@435: void constMethodKlass::oop_follow_contents(ParCompactionManager* cm, duke@435: oop obj) { duke@435: assert (obj->is_constMethod(), "object must be constMethod"); duke@435: constMethodOop cm_oop = constMethodOop(obj); duke@435: PSParallelCompact::mark_and_push(cm, cm_oop->adr_method()); duke@435: PSParallelCompact::mark_and_push(cm, cm_oop->adr_stackmap_data()); duke@435: PSParallelCompact::mark_and_push(cm, cm_oop->adr_exception_table()); duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::constMethodKlassObj never moves. duke@435: } duke@435: #endif // SERIALGC duke@435: duke@435: int constMethodKlass::oop_oop_iterate(oop obj, OopClosure* blk) { duke@435: assert (obj->is_constMethod(), "object must be constMethod"); duke@435: constMethodOop cm = constMethodOop(obj); duke@435: blk->do_oop(cm->adr_method()); duke@435: blk->do_oop(cm->adr_stackmap_data()); duke@435: blk->do_oop(cm->adr_exception_table()); 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 = cm->object_size(); duke@435: return size; duke@435: } duke@435: duke@435: duke@435: int constMethodKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) { duke@435: assert (obj->is_constMethod(), "object must be constMethod"); duke@435: constMethodOop cm = constMethodOop(obj); duke@435: oop* adr; duke@435: adr = cm->adr_method(); duke@435: if (mr.contains(adr)) blk->do_oop(adr); duke@435: adr = cm->adr_stackmap_data(); duke@435: if (mr.contains(adr)) blk->do_oop(adr); duke@435: adr = cm->adr_exception_table(); duke@435: if (mr.contains(adr)) blk->do_oop(adr); 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 = cm->object_size(); duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::constMethodKlassObj never moves. duke@435: return size; duke@435: } duke@435: duke@435: duke@435: int constMethodKlass::oop_adjust_pointers(oop obj) { duke@435: assert(obj->is_constMethod(), "should be constMethod"); duke@435: constMethodOop cm = constMethodOop(obj); duke@435: MarkSweep::adjust_pointer(cm->adr_method()); duke@435: MarkSweep::adjust_pointer(cm->adr_stackmap_data()); duke@435: MarkSweep::adjust_pointer(cm->adr_exception_table()); 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 = cm->object_size(); duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::constMethodKlassObj never moves. duke@435: return size; duke@435: } duke@435: duke@435: #ifndef SERIALGC duke@435: void constMethodKlass::oop_push_contents(PSPromotionManager* pm, oop obj) { duke@435: assert(obj->is_constMethod(), "should be constMethod"); duke@435: } duke@435: duke@435: int constMethodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { duke@435: assert(obj->is_constMethod(), "should be constMethod"); duke@435: constMethodOop cm_oop = constMethodOop(obj); duke@435: #if 0 duke@435: PSParallelCompact::adjust_pointer(cm_oop->adr_method()); duke@435: PSParallelCompact::adjust_pointer(cm_oop->adr_exception_table()); duke@435: PSParallelCompact::adjust_pointer(cm_oop->adr_stackmap_data()); duke@435: #endif duke@435: oop* const beg_oop = cm_oop->oop_block_beg(); duke@435: oop* const end_oop = cm_oop->oop_block_end(); duke@435: for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) { duke@435: PSParallelCompact::adjust_pointer(cur_oop); duke@435: } duke@435: return cm_oop->object_size(); duke@435: } duke@435: duke@435: int constMethodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj, duke@435: HeapWord* beg_addr, duke@435: HeapWord* end_addr) { duke@435: assert(obj->is_constMethod(), "should be constMethod"); duke@435: constMethodOop cm_oop = constMethodOop(obj); duke@435: duke@435: oop* const beg_oop = MAX2((oop*)beg_addr, cm_oop->oop_block_beg()); duke@435: oop* const end_oop = MIN2((oop*)end_addr, cm_oop->oop_block_end()); duke@435: for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) { duke@435: PSParallelCompact::adjust_pointer(cur_oop); duke@435: } duke@435: duke@435: return cm_oop->object_size(); duke@435: } duke@435: #endif // SERIALGC duke@435: duke@435: // Printing duke@435: duke@435: void constMethodKlass::oop_print_on(oop obj, outputStream* st) { duke@435: ResourceMark rm; duke@435: assert(obj->is_constMethod(), "must be constMethod"); duke@435: Klass::oop_print_on(obj, st); duke@435: constMethodOop m = constMethodOop(obj); duke@435: st->print(" - method: " INTPTR_FORMAT " ", (address)m->method()); duke@435: m->method()->print_value_on(st); st->cr(); duke@435: st->print(" - exceptions: " INTPTR_FORMAT "\n", (address)m->exception_table()); duke@435: if (m->has_stackmap_table()) { duke@435: st->print(" - stackmap data: "); duke@435: m->stackmap_data()->print_value_on(st); duke@435: st->cr(); duke@435: } duke@435: } duke@435: duke@435: // Short version of printing constMethodOop - just print the name of the duke@435: // method it belongs to. duke@435: void constMethodKlass::oop_print_value_on(oop obj, outputStream* st) { duke@435: assert(obj->is_constMethod(), "must be constMethod"); duke@435: constMethodOop m = constMethodOop(obj); duke@435: st->print(" const part of method " ); duke@435: m->method()->print_value_on(st); duke@435: } duke@435: duke@435: const char* constMethodKlass::internal_name() const { duke@435: return "{constMethod}"; duke@435: } duke@435: duke@435: duke@435: // Verification duke@435: duke@435: void constMethodKlass::oop_verify_on(oop obj, outputStream* st) { duke@435: Klass::oop_verify_on(obj, st); duke@435: guarantee(obj->is_constMethod(), "object must be constMethod"); duke@435: constMethodOop m = constMethodOop(obj); duke@435: guarantee(m->is_perm(), "should be in permspace"); duke@435: duke@435: // Verification can occur during oop construction before the method or duke@435: // other fields have been initialized. duke@435: if (!obj->partially_loaded()) { duke@435: guarantee(m->method()->is_perm(), "should be in permspace"); duke@435: guarantee(m->method()->is_method(), "should be method"); duke@435: typeArrayOop stackmap_data = m->stackmap_data(); duke@435: guarantee(stackmap_data == NULL || duke@435: stackmap_data->is_perm(), "should be in permspace"); duke@435: guarantee(m->exception_table()->is_perm(), "should be in permspace"); duke@435: guarantee(m->exception_table()->is_typeArray(), "should be type array"); duke@435: duke@435: address m_end = (address)((oop*) m + m->size()); duke@435: address compressed_table_start = m->code_end(); duke@435: guarantee(compressed_table_start <= m_end, "invalid method layout"); duke@435: address compressed_table_end = compressed_table_start; duke@435: // Verify line number table duke@435: if (m->has_linenumber_table()) { duke@435: CompressedLineNumberReadStream stream(m->compressed_linenumber_table()); duke@435: while (stream.read_pair()) { duke@435: guarantee(stream.bci() >= 0 && stream.bci() <= m->code_size(), "invalid bci in line number table"); duke@435: } duke@435: compressed_table_end += stream.position(); duke@435: } duke@435: guarantee(compressed_table_end <= m_end, "invalid method layout"); duke@435: // Verify checked exceptions and local variable tables duke@435: if (m->has_checked_exceptions()) { duke@435: u2* addr = m->checked_exceptions_length_addr(); duke@435: guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout"); duke@435: } duke@435: if (m->has_localvariable_table()) { duke@435: u2* addr = m->localvariable_table_length_addr(); duke@435: guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout"); duke@435: } duke@435: // Check compressed_table_end relative to uncompressed_table_start duke@435: u2* uncompressed_table_start; duke@435: if (m->has_localvariable_table()) { duke@435: uncompressed_table_start = (u2*) m->localvariable_table_start(); duke@435: } else { duke@435: if (m->has_checked_exceptions()) { duke@435: uncompressed_table_start = (u2*) m->checked_exceptions_start(); duke@435: } else { duke@435: uncompressed_table_start = (u2*) m_end; duke@435: } duke@435: } duke@435: int gap = (intptr_t) uncompressed_table_start - (intptr_t) compressed_table_end; duke@435: int max_gap = align_object_size(1)*BytesPerWord; duke@435: guarantee(gap >= 0 && gap < max_gap, "invalid method layout"); duke@435: } duke@435: } duke@435: duke@435: bool constMethodKlass::oop_partially_loaded(oop obj) const { duke@435: assert(obj->is_constMethod(), "object must be klass"); duke@435: constMethodOop m = constMethodOop(obj); duke@435: // check whether exception_table points to self (flag for partially loaded) duke@435: return m->exception_table() == (typeArrayOop)obj; duke@435: } duke@435: duke@435: duke@435: // The exception_table is the last field set when loading an object. duke@435: void constMethodKlass::oop_set_partially_loaded(oop obj) { duke@435: assert(obj->is_constMethod(), "object must be klass"); duke@435: constMethodOop m = constMethodOop(obj); duke@435: // Temporarily set exception_table to point to self duke@435: m->set_exception_table((typeArrayOop)obj); duke@435: }