0N/A/*
3790N/A * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "gc_implementation/shared/markSweep.inline.hpp"
1879N/A#include "interpreter/interpreter.hpp"
1879N/A#include "memory/gcLocker.hpp"
1879N/A#include "memory/resourceArea.hpp"
1879N/A#include "oops/constMethodKlass.hpp"
1879N/A#include "oops/constMethodOop.hpp"
1879N/A#include "oops/oop.inline.hpp"
1879N/A#include "oops/oop.inline2.hpp"
1879N/A#include "runtime/handles.inline.hpp"
0N/A
0N/A
0N/AklassOop constMethodKlass::create_klass(TRAPS) {
0N/A constMethodKlass o;
0N/A KlassHandle h_this_klass(THREAD, Universe::klassKlassObj());
0N/A KlassHandle k = base_create_klass(h_this_klass, header_size(),
0N/A o.vtbl_value(), CHECK_NULL);
0N/A // Make sure size calculation is right
0N/A assert(k()->size() == align_object_size(header_size()),
0N/A "wrong size for object");
0N/A //java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror
0N/A return k();
0N/A}
0N/A
0N/A
0N/Aint constMethodKlass::oop_size(oop obj) const {
0N/A assert(obj->is_constMethod(), "must be constMethod oop");
0N/A return constMethodOop(obj)->object_size();
0N/A}
0N/A
0N/Abool constMethodKlass::oop_is_parsable(oop obj) const {
0N/A assert(obj->is_constMethod(), "must be constMethod oop");
0N/A return constMethodOop(obj)->object_is_parsable();
0N/A}
0N/A
518N/Abool constMethodKlass::oop_is_conc_safe(oop obj) const {
518N/A assert(obj->is_constMethod(), "must be constMethod oop");
518N/A return constMethodOop(obj)->is_conc_safe();
518N/A}
518N/A
0N/AconstMethodOop constMethodKlass::allocate(int byte_code_size,
0N/A int compressed_line_number_size,
0N/A int localvariable_table_length,
3879N/A int exception_table_length,
0N/A int checked_exceptions_length,
518N/A bool is_conc_safe,
0N/A TRAPS) {
0N/A
0N/A int size = constMethodOopDesc::object_size(byte_code_size,
0N/A compressed_line_number_size,
0N/A localvariable_table_length,
3879N/A exception_table_length,
0N/A checked_exceptions_length);
0N/A KlassHandle h_k(THREAD, as_klassOop());
0N/A constMethodOop cm = (constMethodOop)
0N/A CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL);
0N/A assert(!cm->is_parsable(), "Not yet safely parsable");
0N/A No_Safepoint_Verifier no_safepoint;
0N/A cm->set_interpreter_kind(Interpreter::invalid);
0N/A cm->init_fingerprint();
3790N/A cm->set_constants(NULL);
0N/A cm->set_stackmap_data(NULL);
0N/A cm->set_code_size(byte_code_size);
0N/A cm->set_constMethod_size(size);
0N/A cm->set_inlined_tables_length(checked_exceptions_length,
0N/A compressed_line_number_size,
3879N/A localvariable_table_length,
3879N/A exception_table_length);
0N/A assert(cm->size() == size, "wrong size for object");
518N/A cm->set_is_conc_safe(is_conc_safe);
0N/A cm->set_partially_loaded();
0N/A assert(cm->is_parsable(), "Is safely parsable by gc");
0N/A return cm;
0N/A}
0N/A
0N/Avoid constMethodKlass::oop_follow_contents(oop obj) {
0N/A assert (obj->is_constMethod(), "object must be constMethod");
0N/A constMethodOop cm = constMethodOop(obj);
3790N/A MarkSweep::mark_and_push(cm->adr_constants());
0N/A MarkSweep::mark_and_push(cm->adr_stackmap_data());
0N/A // Performance tweak: We skip iterating over the klass pointer since we
0N/A // know that Universe::constMethodKlassObj never moves.
0N/A}
0N/A
0N/A#ifndef SERIALGC
0N/Avoid constMethodKlass::oop_follow_contents(ParCompactionManager* cm,
0N/A oop obj) {
0N/A assert (obj->is_constMethod(), "object must be constMethod");
0N/A constMethodOop cm_oop = constMethodOop(obj);
3790N/A PSParallelCompact::mark_and_push(cm, cm_oop->adr_constants());
0N/A PSParallelCompact::mark_and_push(cm, cm_oop->adr_stackmap_data());
0N/A // Performance tweak: We skip iterating over the klass pointer since we
0N/A // know that Universe::constMethodKlassObj never moves.
0N/A}
0N/A#endif // SERIALGC
0N/A
0N/Aint constMethodKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
0N/A assert (obj->is_constMethod(), "object must be constMethod");
0N/A constMethodOop cm = constMethodOop(obj);
3790N/A blk->do_oop(cm->adr_constants());
0N/A blk->do_oop(cm->adr_stackmap_data());
0N/A // Get size before changing pointers.
0N/A // Don't call size() or oop_size() since that is a virtual call.
0N/A int size = cm->object_size();
0N/A return size;
0N/A}
0N/A
0N/A
0N/Aint constMethodKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
0N/A assert (obj->is_constMethod(), "object must be constMethod");
0N/A constMethodOop cm = constMethodOop(obj);
0N/A oop* adr;
3790N/A adr = cm->adr_constants();
0N/A if (mr.contains(adr)) blk->do_oop(adr);
0N/A adr = cm->adr_stackmap_data();
0N/A if (mr.contains(adr)) blk->do_oop(adr);
0N/A // Get size before changing pointers.
0N/A // Don't call size() or oop_size() since that is a virtual call.
0N/A int size = cm->object_size();
0N/A // Performance tweak: We skip iterating over the klass pointer since we
0N/A // know that Universe::constMethodKlassObj never moves.
0N/A return size;
0N/A}
0N/A
0N/A
0N/Aint constMethodKlass::oop_adjust_pointers(oop obj) {
0N/A assert(obj->is_constMethod(), "should be constMethod");
0N/A constMethodOop cm = constMethodOop(obj);
3790N/A MarkSweep::adjust_pointer(cm->adr_constants());
0N/A MarkSweep::adjust_pointer(cm->adr_stackmap_data());
0N/A // Get size before changing pointers.
0N/A // Don't call size() or oop_size() since that is a virtual call.
0N/A int size = cm->object_size();
0N/A // Performance tweak: We skip iterating over the klass pointer since we
0N/A // know that Universe::constMethodKlassObj never moves.
0N/A return size;
0N/A}
0N/A
0N/A#ifndef SERIALGC
0N/Avoid constMethodKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
0N/A assert(obj->is_constMethod(), "should be constMethod");
0N/A}
0N/A
0N/Aint constMethodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
0N/A assert(obj->is_constMethod(), "should be constMethod");
0N/A constMethodOop cm_oop = constMethodOop(obj);
0N/A oop* const beg_oop = cm_oop->oop_block_beg();
0N/A oop* const end_oop = cm_oop->oop_block_end();
0N/A for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) {
0N/A PSParallelCompact::adjust_pointer(cur_oop);
0N/A }
0N/A return cm_oop->object_size();
0N/A}
0N/A#endif // SERIALGC
0N/A
0N/A// Printing
0N/A
0N/Avoid constMethodKlass::oop_print_on(oop obj, outputStream* st) {
0N/A ResourceMark rm;
0N/A assert(obj->is_constMethod(), "must be constMethod");
0N/A Klass::oop_print_on(obj, st);
0N/A constMethodOop m = constMethodOop(obj);
3790N/A st->print(" - constants: " INTPTR_FORMAT " ", (address)m->constants());
3790N/A m->constants()->print_value_on(st); st->cr();
0N/A if (m->has_stackmap_table()) {
0N/A st->print(" - stackmap data: ");
0N/A m->stackmap_data()->print_value_on(st);
0N/A st->cr();
0N/A }
0N/A}
0N/A
0N/A// Short version of printing constMethodOop - just print the name of the
0N/A// method it belongs to.
0N/Avoid constMethodKlass::oop_print_value_on(oop obj, outputStream* st) {
0N/A assert(obj->is_constMethod(), "must be constMethod");
0N/A constMethodOop m = constMethodOop(obj);
0N/A st->print(" const part of method " );
0N/A m->method()->print_value_on(st);
0N/A}
0N/A
0N/Aconst char* constMethodKlass::internal_name() const {
0N/A return "{constMethod}";
0N/A}
0N/A
0N/A
0N/A// Verification
0N/A
0N/Avoid constMethodKlass::oop_verify_on(oop obj, outputStream* st) {
0N/A Klass::oop_verify_on(obj, st);
0N/A guarantee(obj->is_constMethod(), "object must be constMethod");
0N/A constMethodOop m = constMethodOop(obj);
0N/A guarantee(m->is_perm(), "should be in permspace");
0N/A
0N/A // Verification can occur during oop construction before the method or
0N/A // other fields have been initialized.
0N/A if (!obj->partially_loaded()) {
3790N/A guarantee(m->constants()->is_perm(), "should be in permspace");
3790N/A guarantee(m->constants()->is_constantPool(), "should be constant pool");
0N/A typeArrayOop stackmap_data = m->stackmap_data();
0N/A guarantee(stackmap_data == NULL ||
0N/A stackmap_data->is_perm(), "should be in permspace");
0N/A
0N/A address m_end = (address)((oop*) m + m->size());
0N/A address compressed_table_start = m->code_end();
0N/A guarantee(compressed_table_start <= m_end, "invalid method layout");
0N/A address compressed_table_end = compressed_table_start;
0N/A // Verify line number table
0N/A if (m->has_linenumber_table()) {
0N/A CompressedLineNumberReadStream stream(m->compressed_linenumber_table());
0N/A while (stream.read_pair()) {
0N/A guarantee(stream.bci() >= 0 && stream.bci() <= m->code_size(), "invalid bci in line number table");
0N/A }
0N/A compressed_table_end += stream.position();
0N/A }
0N/A guarantee(compressed_table_end <= m_end, "invalid method layout");
3879N/A // Verify checked exceptions, exception table and local variable tables
0N/A if (m->has_checked_exceptions()) {
0N/A u2* addr = m->checked_exceptions_length_addr();
0N/A guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
0N/A }
3879N/A if (m->has_exception_handler()) {
3879N/A u2* addr = m->exception_table_length_addr();
3879N/A guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
3879N/A }
0N/A if (m->has_localvariable_table()) {
0N/A u2* addr = m->localvariable_table_length_addr();
0N/A guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
0N/A }
0N/A // Check compressed_table_end relative to uncompressed_table_start
0N/A u2* uncompressed_table_start;
0N/A if (m->has_localvariable_table()) {
0N/A uncompressed_table_start = (u2*) m->localvariable_table_start();
3879N/A } else if (m->has_exception_handler()) {
3879N/A uncompressed_table_start = (u2*) m->exception_table_start();
3879N/A } else if (m->has_checked_exceptions()) {
0N/A uncompressed_table_start = (u2*) m->checked_exceptions_start();
3879N/A } else {
0N/A uncompressed_table_start = (u2*) m_end;
0N/A }
0N/A int gap = (intptr_t) uncompressed_table_start - (intptr_t) compressed_table_end;
0N/A int max_gap = align_object_size(1)*BytesPerWord;
0N/A guarantee(gap >= 0 && gap < max_gap, "invalid method layout");
0N/A }
0N/A}
0N/A
0N/Abool constMethodKlass::oop_partially_loaded(oop obj) const {
0N/A assert(obj->is_constMethod(), "object must be klass");
0N/A constMethodOop m = constMethodOop(obj);
3879N/A // check whether stackmap_data points to self (flag for partially loaded)
3879N/A return m->stackmap_data() == (typeArrayOop)obj;
0N/A}
0N/A
0N/A
0N/A// The exception_table is the last field set when loading an object.
0N/Avoid constMethodKlass::oop_set_partially_loaded(oop obj) {
0N/A assert(obj->is_constMethod(), "object must be klass");
0N/A constMethodOop m = constMethodOop(obj);
3879N/A // Temporarily set stackmap_data to point to self
3879N/A m->set_stackmap_data((typeArrayOop)obj);
0N/A}