methodOop.cpp revision 1879
0N/A/*
3845N/A * Copyright (c) 1997, 2010, 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 "classfile/systemDictionary.hpp"
1879N/A#include "code/debugInfoRec.hpp"
1879N/A#include "gc_interface/collectedHeap.inline.hpp"
1879N/A#include "interpreter/bytecodeStream.hpp"
1879N/A#include "interpreter/bytecodeTracer.hpp"
1879N/A#include "interpreter/bytecodes.hpp"
1879N/A#include "interpreter/interpreter.hpp"
1879N/A#include "interpreter/oopMapCache.hpp"
1879N/A#include "memory/gcLocker.hpp"
1879N/A#include "memory/generation.hpp"
1879N/A#include "memory/oopFactory.hpp"
0N/A#include "oops/klassOop.hpp"
0N/A#include "oops/methodDataOop.hpp"
0N/A#include "oops/methodOop.hpp"
0N/A#include "oops/oop.inline.hpp"
0N/A#include "oops/symbolOop.hpp"
0N/A#include "prims/jvmtiExport.hpp"
0N/A#include "prims/methodHandleWalk.hpp"
0N/A#include "prims/nativeLookup.hpp"
0N/A#include "runtime/arguments.hpp"
0N/A#include "runtime/compilationPolicy.hpp"
0N/A#include "runtime/frame.inline.hpp"
0N/A#include "runtime/handles.inline.hpp"
0N/A#include "runtime/relocator.hpp"
0N/A#include "runtime/sharedRuntime.hpp"
0N/A#include "runtime/signature.hpp"
0N/A#include "utilities/xmlstream.hpp"
0N/A
0N/A
0N/A// Implementation of methodOopDesc
0N/A
0N/Aaddress methodOopDesc::get_i2c_entry() {
0N/A assert(_adapter != NULL, "must have");
0N/A return _adapter->get_i2c_entry();
0N/A}
0N/A
0N/Aaddress methodOopDesc::get_c2i_entry() {
0N/A assert(_adapter != NULL, "must have");
0N/A return _adapter->get_c2i_entry();
0N/A}
0N/A
0N/Aaddress methodOopDesc::get_c2i_unverified_entry() {
0N/A assert(_adapter != NULL, "must have");
0N/A return _adapter->get_c2i_unverified_entry();
0N/A}
0N/A
0N/Achar* methodOopDesc::name_and_sig_as_C_string() {
0N/A return name_and_sig_as_C_string(Klass::cast(constants()->pool_holder()), name(), signature());
0N/A}
0N/A
0N/Achar* methodOopDesc::name_and_sig_as_C_string(char* buf, int size) {
0N/A return name_and_sig_as_C_string(Klass::cast(constants()->pool_holder()), name(), signature(), buf, size);
0N/A}
0N/A
0N/Achar* methodOopDesc::name_and_sig_as_C_string(Klass* klass, symbolOop method_name, symbolOop signature) {
0N/A const char* klass_name = klass->external_name();
0N/A int klass_name_len = (int)strlen(klass_name);
0N/A int method_name_len = method_name->utf8_length();
0N/A int len = klass_name_len + 1 + method_name_len + signature->utf8_length();
0N/A char* dest = NEW_RESOURCE_ARRAY(char, len + 1);
0N/A strcpy(dest, klass_name);
0N/A dest[klass_name_len] = '.';
0N/A strcpy(&dest[klass_name_len + 1], method_name->as_C_string());
0N/A strcpy(&dest[klass_name_len + 1 + method_name_len], signature->as_C_string());
0N/A dest[len] = 0;
0N/A return dest;
0N/A}
0N/A
0N/Achar* methodOopDesc::name_and_sig_as_C_string(Klass* klass, symbolOop method_name, symbolOop signature, char* buf, int size) {
0N/A symbolOop klass_name = klass->name();
0N/A klass_name->as_klass_external_name(buf, size);
0N/A int len = (int)strlen(buf);
0N/A
0N/A if (len < size - 1) {
0N/A buf[len++] = '.';
0N/A
0N/A method_name->as_C_string(&(buf[len]), size - len);
0N/A len = (int)strlen(buf);
0N/A
0N/A signature->as_C_string(&(buf[len]), size - len);
0N/A }
0N/A
0N/A return buf;
0N/A}
0N/A
0N/Aint methodOopDesc::fast_exception_handler_bci_for(KlassHandle ex_klass, int throw_bci, TRAPS) {
0N/A // exception table holds quadruple entries of the form (beg_bci, end_bci, handler_bci, klass_index)
0N/A const int beg_bci_offset = 0;
0N/A const int end_bci_offset = 1;
0N/A const int handler_bci_offset = 2;
0N/A const int klass_index_offset = 3;
0N/A const int entry_size = 4;
0N/A // access exception table
0N/A typeArrayHandle table (THREAD, constMethod()->exception_table());
0N/A int length = table->length();
0N/A assert(length % entry_size == 0, "exception table format has changed");
0N/A // iterate through all entries sequentially
0N/A constantPoolHandle pool(THREAD, constants());
0N/A for (int i = 0; i < length; i += entry_size) {
0N/A int beg_bci = table->int_at(i + beg_bci_offset);
0N/A int end_bci = table->int_at(i + end_bci_offset);
0N/A assert(beg_bci <= end_bci, "inconsistent exception table");
0N/A if (beg_bci <= throw_bci && throw_bci < end_bci) {
0N/A // exception handler bci range covers throw_bci => investigate further
0N/A int handler_bci = table->int_at(i + handler_bci_offset);
0N/A int klass_index = table->int_at(i + klass_index_offset);
0N/A if (klass_index == 0) {
0N/A return handler_bci;
0N/A } else if (ex_klass.is_null()) {
0N/A return handler_bci;
0N/A } else {
0N/A // we know the exception class => get the constraint class
0N/A // this may require loading of the constraint class; if verification
0N/A // fails or some other exception occurs, return handler_bci
0N/A klassOop k = pool->klass_at(klass_index, CHECK_(handler_bci));
0N/A KlassHandle klass = KlassHandle(THREAD, k);
0N/A assert(klass.not_null(), "klass not loaded");
0N/A if (ex_klass->is_subtype_of(klass())) {
0N/A return handler_bci;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A return -1;
0N/A}
0N/A
0N/AmethodOop methodOopDesc::method_from_bcp(address bcp) {
0N/A debug_only(static int count = 0; count++);
0N/A assert(Universe::heap()->is_in_permanent(bcp), "bcp not in perm_gen");
0N/A // TO DO: this may be unsafe in some configurations
0N/A HeapWord* p = Universe::heap()->block_start(bcp);
0N/A assert(Universe::heap()->block_is_obj(p), "must be obj");
0N/A assert(oop(p)->is_constMethod(), "not a method");
0N/A return constMethodOop(p)->method();
0N/A}
0N/A
0N/A
0N/Avoid methodOopDesc::mask_for(int bci, InterpreterOopMap* mask) {
0N/A
0N/A Thread* myThread = Thread::current();
0N/A methodHandle h_this(myThread, this);
0N/A#ifdef ASSERT
0N/A bool has_capability = myThread->is_VM_thread() ||
0N/A myThread->is_ConcurrentGC_thread() ||
0N/A myThread->is_GC_task_thread();
0N/A
0N/A if (!has_capability) {
0N/A if (!VerifyStack && !VerifyLastFrame) {
0N/A // verify stack calls this outside VM thread
0N/A warning("oopmap should only be accessed by the "
0N/A "VM, GC task or CMS threads (or during debugging)");
0N/A InterpreterOopMap local_mask;
0N/A instanceKlass::cast(method_holder())->mask_for(h_this, bci, &local_mask);
0N/A local_mask.print();
0N/A }
0N/A }
0N/A#endif
0N/A instanceKlass::cast(method_holder())->mask_for(h_this, bci, mask);
0N/A return;
0N/A}
0N/A
0N/A
0N/Aint methodOopDesc::bci_from(address bcp) const {
0N/A assert(is_native() && bcp == code_base() || contains(bcp) || is_error_reported(), "bcp doesn't belong to this method");
0N/A return bcp - code_base();
0N/A}
0N/A
0N/A
0N/A// Return (int)bcx if it appears to be a valid BCI.
0N/A// Return bci_from((address)bcx) if it appears to be a valid BCP.
0N/A// Return -1 otherwise.
0N/A// Used by profiling code, when invalid data is a possibility.
0N/A// The caller is responsible for validating the methodOop itself.
0N/Aint methodOopDesc::validate_bci_from_bcx(intptr_t bcx) const {
0N/A // keep bci as -1 if not a valid bci
0N/A int bci = -1;
0N/A if (bcx == 0 || (address)bcx == code_base()) {
0N/A // code_size() may return 0 and we allow 0 here
0N/A // the method may be native
0N/A bci = 0;
0N/A } else if (frame::is_bci(bcx)) {
0N/A if (bcx < code_size()) {
0N/A bci = (int)bcx;
0N/A }
0N/A } else if (contains((address)bcx)) {
0N/A bci = (address)bcx - code_base();
0N/A }
0N/A // Assert that if we have dodged any asserts, bci is negative.
0N/A assert(bci == -1 || bci == bci_from(bcp_from(bci)), "sane bci if >=0");
0N/A return bci;
0N/A}
0N/A
0N/Aaddress methodOopDesc::bcp_from(int bci) const {
0N/A assert((is_native() && bci == 0) || (!is_native() && 0 <= bci && bci < code_size()), "illegal bci");
0N/A address bcp = code_base() + bci;
0N/A assert(is_native() && bcp == code_base() || contains(bcp), "bcp doesn't belong to this method");
0N/A return bcp;
0N/A}
0N/A
0N/A
0N/Aint methodOopDesc::object_size(bool is_native) {
0N/A // If native, then include pointers for native_function and signature_handler
0N/A int extra_bytes = (is_native) ? 2*sizeof(address*) : 0;
0N/A int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
0N/A return align_object_size(header_size() + extra_words);
0N/A}
0N/A
0N/A
0N/AsymbolOop methodOopDesc::klass_name() const {
0N/A klassOop k = method_holder();
0N/A assert(k->is_klass(), "must be klass");
0N/A instanceKlass* ik = (instanceKlass*) k->klass_part();
0N/A return ik->name();
0N/A}
0N/A
0N/A
0N/Avoid methodOopDesc::set_interpreter_kind() {
0N/A int kind = Interpreter::method_kind(methodOop(this));
0N/A assert(kind != Interpreter::invalid,
0N/A "interpreter entry must be valid");
0N/A set_interpreter_kind(kind);
0N/A}
0N/A
0N/A
0N/A// Attempt to return method oop to original state. Clear any pointers
0N/A// (to objects outside the shared spaces). We won't be able to predict
0N/A// where they should point in a new JVM. Further initialize some
0N/A// entries now in order allow them to be write protected later.
0N/A
0N/Avoid methodOopDesc::remove_unshareable_info() {
0N/A unlink_method();
0N/A set_interpreter_kind();
0N/A}
0N/A
0N/A
0N/Abool methodOopDesc::was_executed_more_than(int n) {
0N/A // Invocation counter is reset when the methodOop is compiled.
0N/A // If the method has compiled code we therefore assume it has
0N/A // be excuted more than n times.
0N/A if (is_accessor() || is_empty_method() || (code() != NULL)) {
0N/A // interpreter doesn't bump invocation counter of trivial methods
0N/A // compiler does not bump invocation counter of compiled methods
0N/A return true;
0N/A }
0N/A else if (_invocation_counter.carry() || (method_data() != NULL && method_data()->invocation_counter()->carry())) {
0N/A // The carry bit is set when the counter overflows and causes
0N/A // a compilation to occur. We don't know how many times
0N/A // the counter has been reset, so we simply assume it has
0N/A // been executed more than n times.
0N/A return true;
0N/A } else {
0N/A return invocation_count() > n;
0N/A }
0N/A}
0N/A
0N/A#ifndef PRODUCT
0N/Avoid methodOopDesc::print_invocation_count() {
0N/A if (is_static()) tty->print("static ");
0N/A if (is_final()) tty->print("final ");
0N/A if (is_synchronized()) tty->print("synchronized ");
0N/A if (is_native()) tty->print("native ");
0N/A method_holder()->klass_part()->name()->print_symbol_on(tty);
0N/A tty->print(".");
0N/A name()->print_symbol_on(tty);
0N/A signature()->print_symbol_on(tty);
0N/A
0N/A if (WizardMode) {
0N/A // dump the size of the byte codes
0N/A tty->print(" {%d}", code_size());
0N/A }
0N/A tty->cr();
0N/A
4022N/A tty->print_cr (" interpreter_invocation_count: %8d ", interpreter_invocation_count());
4022N/A tty->print_cr (" invocation_counter: %8d ", invocation_count());
4022N/A tty->print_cr (" backedge_counter: %8d ", backedge_count());
4022N/A if (CountCompiledCalls) {
4022N/A tty->print_cr (" compiled_invocation_count: %8d ", compiled_invocation_count());
4022N/A }
4022N/A
4022N/A}
0N/A#endif
0N/A
0N/A// Build a methodDataOop object to hold information about this method
0N/A// collected in the interpreter.
0N/Avoid methodOopDesc::build_interpreter_method_data(methodHandle method, TRAPS) {
0N/A // Grab a lock here to prevent multiple
0N/A // methodDataOops from being created.
0N/A MutexLocker ml(MethodData_lock, THREAD);
0N/A if (method->method_data() == NULL) {
0N/A methodDataOop method_data = oopFactory::new_methodData(method, CHECK);
0N/A method->set_method_data(method_data);
0N/A if (PrintMethodData && (Verbose || WizardMode)) {
0N/A ResourceMark rm(THREAD);
0N/A tty->print("build_interpreter_method_data for ");
0N/A method->print_name(tty);
0N/A tty->cr();
0N/A // At the end of the run, the MDO, full of data, will be dumped.
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid methodOopDesc::cleanup_inline_caches() {
0N/A // The current system doesn't use inline caches in the interpreter
0N/A // => nothing to do (keep this method around for future use)
0N/A}
0N/A
0N/A
0N/Aint methodOopDesc::extra_stack_words() {
0N/A // not an inline function, to avoid a header dependency on Interpreter
0N/A return extra_stack_entries() * Interpreter::stackElementSize;
0N/A}
0N/A
0N/A
0N/Avoid methodOopDesc::compute_size_of_parameters(Thread *thread) {
0N/A symbolHandle h_signature(thread, signature());
0N/A ArgumentSizeComputer asc(h_signature);
0N/A set_size_of_parameters(asc.size() + (is_static() ? 0 : 1));
0N/A}
0N/A
0N/A#ifdef CC_INTERP
0N/Avoid methodOopDesc::set_result_index(BasicType type) {
0N/A _result_index = Interpreter::BasicType_as_index(type);
0N/A}
0N/A#endif
0N/A
0N/ABasicType methodOopDesc::result_type() const {
0N/A ResultTypeFinder rtf(signature());
0N/A return rtf.type();
0N/A}
0N/A
0N/A
0N/Abool methodOopDesc::is_empty_method() const {
0N/A return code_size() == 1
0N/A && *code_base() == Bytecodes::_return;
0N/A}
0N/A
0N/A
0N/Abool methodOopDesc::is_vanilla_constructor() const {
0N/A // Returns true if this method is a vanilla constructor, i.e. an "<init>" "()V" method
0N/A // which only calls the superclass vanilla constructor and possibly does stores of
0N/A // zero constants to local fields:
0N/A //
0N/A // aload_0
0N/A // invokespecial
0N/A // indexbyte1
0N/A // indexbyte2
0N/A //
0N/A // followed by an (optional) sequence of:
0N/A //
0N/A // aload_0
0N/A // aconst_null / iconst_0 / fconst_0 / dconst_0
0N/A // putfield
0N/A // indexbyte1
0N/A // indexbyte2
0N/A //
0N/A // followed by:
0N/A //
0N/A // return
0N/A
0N/A assert(name() == vmSymbols::object_initializer_name(), "Should only be called for default constructors");
0N/A assert(signature() == vmSymbols::void_method_signature(), "Should only be called for default constructors");
0N/A int size = code_size();
0N/A // Check if size match
0N/A if (size == 0 || size % 5 != 0) return false;
0N/A address cb = code_base();
0N/A int last = size - 1;
0N/A if (cb[0] != Bytecodes::_aload_0 || cb[1] != Bytecodes::_invokespecial || cb[last] != Bytecodes::_return) {
0N/A // Does not call superclass default constructor
0N/A return false;
0N/A }
0N/A // Check optional sequence
0N/A for (int i = 4; i < last; i += 5) {
0N/A if (cb[i] != Bytecodes::_aload_0) return false;
0N/A if (!Bytecodes::is_zero_const(Bytecodes::cast(cb[i+1]))) return false;
0N/A if (cb[i+2] != Bytecodes::_putfield) return false;
0N/A }
0N/A return true;
0N/A}
0N/A
0N/A
0N/Abool methodOopDesc::compute_has_loops_flag() {
0N/A BytecodeStream bcs(methodOop(this));
0N/A Bytecodes::Code bc;
0N/A
0N/A while ((bc = bcs.next()) >= 0) {
0N/A switch( bc ) {
0N/A case Bytecodes::_ifeq:
0N/A case Bytecodes::_ifnull:
0N/A case Bytecodes::_iflt:
0N/A case Bytecodes::_ifle:
0N/A case Bytecodes::_ifne:
0N/A case Bytecodes::_ifnonnull:
0N/A case Bytecodes::_ifgt:
0N/A case Bytecodes::_ifge:
0N/A case Bytecodes::_if_icmpeq:
0N/A case Bytecodes::_if_icmpne:
0N/A case Bytecodes::_if_icmplt:
0N/A case Bytecodes::_if_icmpgt:
0N/A case Bytecodes::_if_icmple:
0N/A case Bytecodes::_if_icmpge:
0N/A case Bytecodes::_if_acmpeq:
0N/A case Bytecodes::_if_acmpne:
0N/A case Bytecodes::_goto:
0N/A case Bytecodes::_jsr:
0N/A if( bcs.dest() < bcs.next_bci() ) _access_flags.set_has_loops();
0N/A break;
0N/A
0N/A case Bytecodes::_goto_w:
0N/A case Bytecodes::_jsr_w:
0N/A if( bcs.dest_w() < bcs.next_bci() ) _access_flags.set_has_loops();
0N/A break;
0N/A }
0N/A }
0N/A _access_flags.set_loops_flag_init();
0N/A return _access_flags.has_loops();
0N/A}
0N/A
0N/A
0N/Abool methodOopDesc::is_final_method() const {
0N/A // %%% Should return true for private methods also,
0N/A // since there is no way to override them.
0N/A return is_final() || Klass::cast(method_holder())->is_final();
0N/A}
0N/A
0N/A
0N/Abool methodOopDesc::is_strict_method() const {
0N/A return is_strict();
0N/A}
0N/A
0N/A
0N/Abool methodOopDesc::can_be_statically_bound() const {
0N/A if (is_final_method()) return true;
0N/A return vtable_index() == nonvirtual_vtable_index;
0N/A}
0N/A
0N/A
0N/Abool methodOopDesc::is_accessor() const {
0N/A if (code_size() != 5) return false;
0N/A if (size_of_parameters() != 1) return false;
0N/A methodOop m = (methodOop)this; // pass to code_at() to avoid method_from_bcp
0N/A if (Bytecodes::java_code_at(code_base()+0, m) != Bytecodes::_aload_0 ) return false;
0N/A if (Bytecodes::java_code_at(code_base()+1, m) != Bytecodes::_getfield) return false;
0N/A if (Bytecodes::java_code_at(code_base()+4, m) != Bytecodes::_areturn &&
0N/A Bytecodes::java_code_at(code_base()+4, m) != Bytecodes::_ireturn ) return false;
0N/A return true;
0N/A}
0N/A
0N/A
0N/Abool methodOopDesc::is_initializer() const {
0N/A return name() == vmSymbols::object_initializer_name() || name() == vmSymbols::class_initializer_name();
0N/A}
0N/A
0N/A
0N/AobjArrayHandle methodOopDesc::resolved_checked_exceptions_impl(methodOop this_oop, TRAPS) {
0N/A int length = this_oop->checked_exceptions_length();
0N/A if (length == 0) { // common case
0N/A return objArrayHandle(THREAD, Universe::the_empty_class_klass_array());
0N/A } else {
0N/A methodHandle h_this(THREAD, this_oop);
0N/A objArrayOop m_oop = oopFactory::new_objArray(SystemDictionary::Class_klass(), length, CHECK_(objArrayHandle()));
0N/A objArrayHandle mirrors (THREAD, m_oop);
0N/A for (int i = 0; i < length; i++) {
0N/A CheckedExceptionElement* table = h_this->checked_exceptions_start(); // recompute on each iteration, not gc safe
0N/A klassOop k = h_this->constants()->klass_at(table[i].class_cp_index, CHECK_(objArrayHandle()));
0N/A assert(Klass::cast(k)->is_subclass_of(SystemDictionary::Throwable_klass()), "invalid exception class");
0N/A mirrors->obj_at_put(i, Klass::cast(k)->java_mirror());
0N/A }
0N/A return mirrors;
0N/A }
0N/A};
0N/A
0N/A
0N/Aint methodOopDesc::line_number_from_bci(int bci) const {
0N/A if (bci == SynchronizationEntryBCI) bci = 0;
0N/A assert(bci == 0 || 0 <= bci && bci < code_size(), "illegal bci");
0N/A int best_bci = 0;
0N/A int best_line = -1;
0N/A
0N/A if (has_linenumber_table()) {
0N/A // The line numbers are a short array of 2-tuples [start_pc, line_number].
0N/A // Not necessarily sorted and not necessarily one-to-one.
0N/A CompressedLineNumberReadStream stream(compressed_linenumber_table());
0N/A while (stream.read_pair()) {
0N/A if (stream.bci() == bci) {
0N/A // perfect match
0N/A return stream.line();
0N/A } else {
0N/A // update best_bci/line
0N/A if (stream.bci() < bci && stream.bci() >= best_bci) {
0N/A best_bci = stream.bci();
0N/A best_line = stream.line();
0N/A }
0N/A }
0N/A }
0N/A }
0N/A return best_line;
0N/A}
0N/A
0N/A
0N/Abool methodOopDesc::is_klass_loaded_by_klass_index(int klass_index) const {
0N/A if( _constants->tag_at(klass_index).is_unresolved_klass() ) {
0N/A Thread *thread = Thread::current();
0N/A symbolHandle klass_name(thread, _constants->klass_name_at(klass_index));
0N/A Handle loader(thread, instanceKlass::cast(method_holder())->class_loader());
0N/A Handle prot (thread, Klass::cast(method_holder())->protection_domain());
0N/A return SystemDictionary::find(klass_name, loader, prot, thread) != NULL;
0N/A } else {
0N/A return true;
0N/A }
0N/A}
0N/A
0N/A
0N/Abool methodOopDesc::is_klass_loaded(int refinfo_index, bool must_be_resolved) const {
0N/A int klass_index = _constants->klass_ref_index_at(refinfo_index);
0N/A if (must_be_resolved) {
0N/A // Make sure klass is resolved in constantpool.
0N/A if (constants()->tag_at(klass_index).is_unresolved_klass()) return false;
0N/A }
0N/A return is_klass_loaded_by_klass_index(klass_index);
0N/A}
0N/A
0N/A
0N/Avoid methodOopDesc::set_native_function(address function, bool post_event_flag) {
0N/A assert(function != NULL, "use clear_native_function to unregister natives");
0N/A address* native_function = native_function_addr();
0N/A
0N/A // We can see racers trying to place the same native function into place. Once
0N/A // is plenty.
0N/A address current = *native_function;
0N/A if (current == function) return;
0N/A if (post_event_flag && JvmtiExport::should_post_native_method_bind() &&
0N/A function != NULL) {
0N/A // native_method_throw_unsatisfied_link_error_entry() should only
0N/A // be passed when post_event_flag is false.
0N/A assert(function !=
0N/A SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
0N/A "post_event_flag mis-match");
0N/A
0N/A // post the bind event, and possible change the bind function
0N/A JvmtiExport::post_native_method_bind(this, &function);
0N/A }
0N/A *native_function = function;
0N/A // This function can be called more than once. We must make sure that we always
0N/A // use the latest registered method -> check if a stub already has been generated.
0N/A // If so, we have to make it not_entrant.
0N/A nmethod* nm = code(); // Put it into local variable to guard against concurrent updates
0N/A if (nm != NULL) {
0N/A nm->make_not_entrant();
0N/A }
0N/A}
0N/A
0N/A
0N/Abool methodOopDesc::has_native_function() const {
0N/A address func = native_function();
0N/A return (func != NULL && func != SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
0N/A}
0N/A
0N/A
0N/Avoid methodOopDesc::clear_native_function() {
0N/A set_native_function(
0N/A SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
0N/A !native_bind_event_is_interesting);
0N/A clear_code();
0N/A}
0N/A
0N/A
0N/Avoid methodOopDesc::set_signature_handler(address handler) {
0N/A address* signature_handler = signature_handler_addr();
0N/A *signature_handler = handler;
0N/A}
0N/A
0N/A
0N/Abool methodOopDesc::is_not_compilable(int comp_level) const {
0N/A if (is_method_handle_invoke()) {
0N/A // compilers must recognize this method specially, or not at all
0N/A return true;
0N/A }
0N/A if (number_of_breakpoints() > 0) {
0N/A return true;
0N/A }
0N/A if (comp_level == CompLevel_any) {
0N/A return is_not_c1_compilable() || is_not_c2_compilable();
0N/A }
0N/A if (is_c1_compile(comp_level)) {
0N/A return is_not_c1_compilable();
0N/A }
0N/A if (is_c2_compile(comp_level)) {
0N/A return is_not_c2_compilable();
0N/A }
0N/A return false;
0N/A}
0N/A
0N/A// call this when compiler finds that this method is not compilable
0N/Avoid methodOopDesc::set_not_compilable(int comp_level, bool report) {
0N/A if (PrintCompilation && report) {
0N/A ttyLocker ttyl;
0N/A tty->print("made not compilable ");
0N/A this->print_short_name(tty);
0N/A int size = this->code_size();
0N/A if (size > 0)
0N/A tty->print(" (%d bytes)", size);
0N/A tty->cr();
0N/A }
0N/A if ((TraceDeoptimization || LogCompilation) && (xtty != NULL)) {
0N/A ttyLocker ttyl;
0N/A xtty->begin_elem("make_not_compilable thread='%d'", (int) os::current_thread_id());
0N/A xtty->method(methodOop(this));
0N/A xtty->stamp();
0N/A xtty->end_elem();
0N/A }
0N/A if (comp_level == CompLevel_all) {
0N/A set_not_c1_compilable();
0N/A set_not_c2_compilable();
0N/A } else {
0N/A if (is_c1_compile(comp_level)) {
0N/A set_not_c1_compilable();
0N/A } else
0N/A if (is_c2_compile(comp_level)) {
0N/A set_not_c2_compilable();
0N/A }
0N/A }
0N/A CompilationPolicy::policy()->disable_compilation(this);
0N/A}
0N/A
0N/A// Revert to using the interpreter and clear out the nmethod
0N/Avoid methodOopDesc::clear_code() {
0N/A
0N/A // this may be NULL if c2i adapters have not been made yet
0N/A // Only should happen at allocate time.
0N/A if (_adapter == NULL) {
0N/A _from_compiled_entry = NULL;
0N/A } else {
0N/A _from_compiled_entry = _adapter->get_c2i_entry();
0N/A }
0N/A OrderAccess::storestore();
0N/A _from_interpreted_entry = _i2i_entry;
0N/A OrderAccess::storestore();
0N/A _code = NULL;
0N/A}
0N/A
0N/A// Called by class data sharing to remove any entry points (which are not shared)
0N/Avoid methodOopDesc::unlink_method() {
0N/A _code = NULL;
0N/A _i2i_entry = NULL;
0N/A _from_interpreted_entry = NULL;
0N/A if (is_native()) {
0N/A *native_function_addr() = NULL;
0N/A set_signature_handler(NULL);
0N/A }
0N/A NOT_PRODUCT(set_compiled_invocation_count(0);)
0N/A invocation_counter()->reset();
0N/A backedge_counter()->reset();
0N/A _adapter = NULL;
0N/A _from_compiled_entry = NULL;
0N/A assert(_method_data == NULL, "unexpected method data?");
0N/A set_method_data(NULL);
0N/A set_interpreter_throwout_count(0);
0N/A set_interpreter_invocation_count(0);
0N/A}
0N/A
0N/A// Called when the method_holder is getting linked. Setup entrypoints so the method
0N/A// is ready to be called from interpreter, compiler, and vtables.
0N/Avoid methodOopDesc::link_method(methodHandle h_method, TRAPS) {
0N/A assert(_i2i_entry == NULL, "should only be called once");
0N/A assert(_adapter == NULL, "init'd to NULL" );
0N/A assert( _code == NULL, "nothing compiled yet" );
0N/A
0N/A // Setup interpreter entrypoint
0N/A assert(this == h_method(), "wrong h_method()" );
0N/A address entry = Interpreter::entry_for_method(h_method);
0N/A assert(entry != NULL, "interpreter entry must be non-null");
0N/A // Sets both _i2i_entry and _from_interpreted_entry
0N/A set_interpreter_entry(entry);
0N/A if (is_native() && !is_method_handle_invoke()) {
0N/A set_native_function(
0N/A SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
0N/A !native_bind_event_is_interesting);
0N/A }
0N/A
0N/A // Setup compiler entrypoint. This is made eagerly, so we do not need
0N/A // special handling of vtables. An alternative is to make adapters more
0N/A // lazily by calling make_adapter() from from_compiled_entry() for the
0N/A // normal calls. For vtable calls life gets more complicated. When a
0N/A // call-site goes mega-morphic we need adapters in all methods which can be
0N/A // called from the vtable. We need adapters on such methods that get loaded
0N/A // later. Ditto for mega-morphic itable calls. If this proves to be a
0N/A // problem we'll make these lazily later.
0N/A (void) make_adapters(h_method, CHECK);
0N/A
0N/A // ONLY USE the h_method now as make_adapter may have blocked
0N/A
0N/A}
0N/A
0N/Aaddress methodOopDesc::make_adapters(methodHandle mh, TRAPS) {
0N/A // Adapters for compiled code are made eagerly here. They are fairly
0N/A // small (generally < 100 bytes) and quick to make (and cached and shared)
0N/A // so making them eagerly shouldn't be too expensive.
0N/A AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh);
0N/A if (adapter == NULL ) {
0N/A THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(), "out of space in CodeCache for adapters");
0N/A }
0N/A
0N/A mh->set_adapter_entry(adapter);
0N/A mh->_from_compiled_entry = adapter->get_c2i_entry();
0N/A return adapter->get_c2i_entry();
0N/A}
0N/A
0N/A// The verified_code_entry() must be called when a invoke is resolved
0N/A// on this method.
0N/A
0N/A// It returns the compiled code entry point, after asserting not null.
0N/A// This function is called after potential safepoints so that nmethod
0N/A// or adapter that it points to is still live and valid.
0N/A// This function must not hit a safepoint!
0N/Aaddress methodOopDesc::verified_code_entry() {
0N/A debug_only(No_Safepoint_Verifier nsv;)
0N/A nmethod *code = (nmethod *)OrderAccess::load_ptr_acquire(&_code);
0N/A if (code == NULL && UseCodeCacheFlushing) {
0N/A nmethod *saved_code = CodeCache::find_and_remove_saved_code(this);
0N/A if (saved_code != NULL) {
0N/A methodHandle method(this);
0N/A assert( ! saved_code->is_osr_method(), "should not get here for osr" );
0N/A set_code( method, saved_code );
0N/A }
0N/A }
0N/A
0N/A assert(_from_compiled_entry != NULL, "must be set");
2126N/A return _from_compiled_entry;
2126N/A}
2126N/A
0N/A// Check that if an nmethod ref exists, it has a backlink to this or no backlink at all
0N/A// (could be racing a deopt).
0N/A// Not inline to avoid circular ref.
0N/Abool methodOopDesc::check_code() const {
0N/A // cached in a register or local. There's a race on the value of the field.
0N/A nmethod *code = (nmethod *)OrderAccess::load_ptr_acquire(&_code);
0N/A return code == NULL || (code->method() == NULL) || (code->method() == (methodOop)this && !code->is_osr_method());
0N/A}
0N/A
0N/A// Install compiled code. Instantly it can execute.
0N/Avoid methodOopDesc::set_code(methodHandle mh, nmethod *code) {
0N/A assert( code, "use clear_code to remove code" );
0N/A assert( mh->check_code(), "" );
0N/A
0N/A guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
0N/A
0N/A // These writes must happen in this order, because the interpreter will
0N/A // directly jump to from_interpreted_entry which jumps to an i2c adapter
0N/A // which jumps to _from_compiled_entry.
0N/A mh->_code = code; // Assign before allowing compiled code to exec
0N/A
0N/A int comp_level = code->comp_level();
0N/A // In theory there could be a race here. In practice it is unlikely
0N/A // and not worth worrying about.
0N/A if (comp_level > mh->highest_comp_level()) {
0N/A mh->set_highest_comp_level(comp_level);
0N/A }
0N/A
0N/A OrderAccess::storestore();
0N/A#ifdef SHARK
0N/A mh->_from_interpreted_entry = code->insts_begin();
0N/A#else
0N/A mh->_from_compiled_entry = code->verified_entry_point();
0N/A OrderAccess::storestore();
0N/A // Instantly compiled code can execute.
0N/A mh->_from_interpreted_entry = mh->get_i2c_entry();
0N/A#endif // SHARK
0N/A
0N/A}
0N/A
0N/A
0N/Abool methodOopDesc::is_overridden_in(klassOop k) const {
0N/A instanceKlass* ik = instanceKlass::cast(k);
0N/A
0N/A if (ik->is_interface()) return false;
0N/A
0N/A // If method is an interface, we skip it - except if it
0N/A // is a miranda method
0N/A if (instanceKlass::cast(method_holder())->is_interface()) {
0N/A // Check that method is not a miranda method
0N/A if (ik->lookup_method(name(), signature()) == NULL) {
0N/A // No implementation exist - so miranda method
0N/A return false;
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A assert(ik->is_subclass_of(method_holder()), "should be subklass");
0N/A assert(ik->vtable() != NULL, "vtable should exist");
0N/A if (vtable_index() == nonvirtual_vtable_index) {
0N/A return false;
0N/A } else {
0N/A methodOop vt_m = ik->method_at_vtable(vtable_index());
0N/A return vt_m != methodOop(this);
0N/A }
0N/A}
0N/A
0N/A
0N/A// give advice about whether this methodOop should be cached or not
0N/Abool methodOopDesc::should_not_be_cached() const {
0N/A if (is_old()) {
0N/A // This method has been redefined. It is either EMCP or obsolete
0N/A // and we don't want to cache it because that would pin the method
0N/A // down and prevent it from being collectible if and when it
0N/A // finishes executing.
0N/A return true;
0N/A }
0N/A
0N/A if (mark()->should_not_be_cached()) {
65N/A // It is either not safe or not a good idea to cache this
0N/A // method at this time because of the state of the embedded
0N/A // markOop. See markOop.cpp for the gory details.
0N/A return true;
0N/A }
0N/A
0N/A // caching this method should be just fine
0N/A return false;
3058N/A}
3058N/A
3058N/Abool methodOopDesc::is_method_handle_invoke_name(vmSymbols::SID name_sid) {
3058N/A switch (name_sid) {
3058N/A case vmSymbols::VM_SYMBOL_ENUM_NAME(invokeExact_name):
3058N/A case vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name):
3058N/A return true;
3058N/A }
3058N/A if (AllowTransitionalJSR292
3058N/A && name_sid == vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name))
3058N/A return true;
3058N/A return false;
3058N/A}
3058N/A
0N/A// Constant pool structure for invoke methods:
0N/Aenum {
0N/A _imcp_invoke_name = 1, // utf8: 'invokeExact' or 'invokeGeneric'
0N/A _imcp_invoke_signature, // utf8: (variable symbolOop)
65N/A _imcp_method_type_value, // string: (variable java/dyn/MethodType, sic)
0N/A _imcp_limit
0N/A};
0N/A
0N/Aoop methodOopDesc::method_handle_type() const {
0N/A if (!is_method_handle_invoke()) { assert(false, "caller resp."); return NULL; }
0N/A oop mt = constants()->resolved_string_at(_imcp_method_type_value);
0N/A assert(mt->klass() == SystemDictionary::MethodType_klass(), "");
0N/A return mt;
0N/A}
0N/A
0N/Ajint* methodOopDesc::method_type_offsets_chain() {
0N/A static jint pchase[] = { -1, -1, -1 };
0N/A if (pchase[0] == -1) {
0N/A jint step0 = in_bytes(constants_offset());
0N/A jint step1 = (constantPoolOopDesc::header_size() + _imcp_method_type_value) * HeapWordSize;
0N/A // do this in reverse to avoid races:
0N/A OrderAccess::release_store(&pchase[1], step1);
0N/A OrderAccess::release_store(&pchase[0], step0);
0N/A }
0N/A return pchase;
0N/A}
0N/A
0N/A//------------------------------------------------------------------------------
0N/A// methodOopDesc::is_method_handle_adapter
0N/A//
0N/A// Tests if this method is an internal adapter frame from the
0N/A// MethodHandleCompiler.
0N/A// Must be consistent with MethodHandleCompiler::get_method_oop().
0N/Abool methodOopDesc::is_method_handle_adapter() const {
0N/A if (is_synthetic() &&
0N/A !is_native() && // has code from MethodHandleCompiler
0N/A is_method_handle_invoke_name(name()) &&
0N/A MethodHandleCompiler::klass_is_method_handle_adapter_holder(method_holder())) {
0N/A assert(!is_method_handle_invoke(), "disjoint");
0N/A return true;
0N/A } else {
0N/A return false;
0N/A }
0N/A}
0N/A
0N/AmethodHandle methodOopDesc::make_invoke_method(KlassHandle holder,
0N/A symbolHandle name,
0N/A symbolHandle signature,
0N/A Handle method_type, TRAPS) {
0N/A methodHandle empty;
0N/A
0N/A assert(holder() == SystemDictionary::MethodHandle_klass(),
0N/A "must be a JSR 292 magic type");
0N/A
0N/A if (TraceMethodHandles) {
0N/A tty->print("Creating invoke method for ");
0N/A signature->print_value();
0N/A tty->cr();
0N/A }
0N/A
0N/A constantPoolHandle cp;
0N/A {
0N/A constantPoolOop cp_oop = oopFactory::new_constantPool(_imcp_limit, IsSafeConc, CHECK_(empty));
0N/A cp = constantPoolHandle(THREAD, cp_oop);
0N/A }
0N/A cp->symbol_at_put(_imcp_invoke_name, name());
0N/A cp->symbol_at_put(_imcp_invoke_signature, signature());
0N/A cp->string_at_put(_imcp_method_type_value, vmSymbols::void_signature());
0N/A cp->set_pool_holder(holder());
0N/A
0N/A // set up the fancy stuff:
0N/A cp->pseudo_string_at_put(_imcp_method_type_value, method_type());
0N/A methodHandle m;
0N/A {
0N/A int flags_bits = (JVM_MH_INVOKE_BITS | JVM_ACC_PUBLIC | JVM_ACC_FINAL);
0N/A methodOop m_oop = oopFactory::new_method(0, accessFlags_from(flags_bits),
0N/A 0, 0, 0, IsSafeConc, CHECK_(empty));
0N/A m = methodHandle(THREAD, m_oop);
0N/A }
0N/A m->set_constants(cp());
0N/A m->set_name_index(_imcp_invoke_name);
0N/A m->set_signature_index(_imcp_invoke_signature);
0N/A assert(is_method_handle_invoke_name(m->name()), "");
0N/A assert(m->signature() == signature(), "");
0N/A assert(m->is_method_handle_invoke(), "");
0N/A#ifdef CC_INTERP
0N/A ResultTypeFinder rtf(signature());
0N/A m->set_result_index(rtf.type());
0N/A#endif
0N/A m->compute_size_of_parameters(THREAD);
0N/A m->set_exception_table(Universe::the_empty_int_array());
0N/A m->init_intrinsic_id();
0N/A assert(m->intrinsic_id() == vmIntrinsics::_invokeExact ||
0N/A m->intrinsic_id() == vmIntrinsics::_invokeGeneric, "must be an invoker");
0N/A
0N/A // Finally, set up its entry points.
0N/A assert(m->method_handle_type() == method_type(), "");
0N/A assert(m->can_be_statically_bound(), "");
0N/A m->set_vtable_index(methodOopDesc::nonvirtual_vtable_index);
0N/A m->link_method(m, CHECK_(empty));
0N/A
0N/A#ifdef ASSERT
0N/A // Make sure the pointer chase works.
0N/A address p = (address) m();
0N/A for (jint* pchase = method_type_offsets_chain(); (*pchase) != -1; pchase++) {
0N/A p = *(address*)(p + (*pchase));
0N/A }
0N/A assert((oop)p == method_type(), "pointer chase is correct");
0N/A#endif
0N/A
0N/A if (TraceMethodHandles && (Verbose || WizardMode))
0N/A m->print_on(tty);
0N/A
0N/A return m;
0N/A}
0N/A
0N/A
0N/A
0N/AmethodHandle methodOopDesc:: clone_with_new_data(methodHandle m, u_char* new_code, int new_code_length,
0N/A u_char* new_compressed_linenumber_table, int new_compressed_linenumber_size, TRAPS) {
0N/A // Code below does not work for native methods - they should never get rewritten anyway
0N/A assert(!m->is_native(), "cannot rewrite native methods");
0N/A // Allocate new methodOop
0N/A AccessFlags flags = m->access_flags();
0N/A int checked_exceptions_len = m->checked_exceptions_length();
0N/A int localvariable_len = m->localvariable_table_length();
0N/A // Allocate newm_oop with the is_conc_safe parameter set
0N/A // to IsUnsafeConc to indicate that newm_oop is not yet
0N/A // safe for concurrent processing by a GC.
0N/A methodOop newm_oop = oopFactory::new_method(new_code_length,
0N/A flags,
0N/A new_compressed_linenumber_size,
0N/A localvariable_len,
0N/A checked_exceptions_len,
0N/A IsUnsafeConc,
0N/A CHECK_(methodHandle()));
0N/A methodHandle newm (THREAD, newm_oop);
0N/A int new_method_size = newm->method_size();
0N/A // Create a shallow copy of methodOopDesc part, but be careful to preserve the new constMethodOop
0N/A constMethodOop newcm = newm->constMethod();
0N/A int new_const_method_size = newm->constMethod()->object_size();
0N/A
0N/A memcpy(newm(), m(), sizeof(methodOopDesc));
0N/A // Create shallow copy of constMethodOopDesc, but be careful to preserve the methodOop
0N/A // is_conc_safe is set to false because that is the value of
0N/A // is_conc_safe initialzied into newcm and the copy should
605N/A // not overwrite that value. During the window during which it is
605N/A // tagged as unsafe, some extra work could be needed during precleaning
605N/A // or concurrent marking but those phases will be correct. Setting and
605N/A // resetting is done in preference to a careful copying into newcm to
605N/A // avoid having to know the precise layout of a constMethodOop.
605N/A m->constMethod()->set_is_conc_safe(false);
0N/A memcpy(newcm, m->constMethod(), sizeof(constMethodOopDesc));
605N/A m->constMethod()->set_is_conc_safe(true);
605N/A // Reset correct method/const method, method size, and parameter info
0N/A newcm->set_method(newm());
605N/A newm->set_constMethod(newcm);
4022N/A assert(newcm->method() == newm(), "check");
0N/A newm->constMethod()->set_code_size(new_code_length);
0N/A newm->constMethod()->set_constMethod_size(new_const_method_size);
605N/A newm->set_method_size(new_method_size);
4022N/A assert(newm->code_size() == new_code_length, "check");
4022N/A assert(newm->checked_exceptions_length() == checked_exceptions_len, "check");
0N/A assert(newm->localvariable_table_length() == localvariable_len, "check");
0N/A // Copy new byte codes
4022N/A memcpy(newm->code_base(), new_code, new_code_length);
0N/A // Copy line number table
0N/A if (new_compressed_linenumber_size > 0) {
0N/A memcpy(newm->compressed_linenumber_table(),
0N/A new_compressed_linenumber_table,
0N/A new_compressed_linenumber_size);
0N/A }
0N/A // Copy checked_exceptions
0N/A if (checked_exceptions_len > 0) {
0N/A memcpy(newm->checked_exceptions_start(),
0N/A m->checked_exceptions_start(),
0N/A checked_exceptions_len * sizeof(CheckedExceptionElement));
0N/A }
0N/A // Copy local variable number table
0N/A if (localvariable_len > 0) {
0N/A memcpy(newm->localvariable_table_start(),
0N/A m->localvariable_table_start(),
0N/A localvariable_len * sizeof(LocalVariableTableElement));
0N/A }
0N/A
0N/A // Only set is_conc_safe to true when changes to newcm are
0N/A // complete.
0N/A newcm->set_is_conc_safe(true);
0N/A return newm;
0N/A}
0N/A
0N/AvmSymbols::SID methodOopDesc::klass_id_for_intrinsics(klassOop holder) {
0N/A // if loader is not the default loader (i.e., != NULL), we can't know the intrinsics
0N/A // because we are not loading from core libraries
0N/A if (instanceKlass::cast(holder)->class_loader() != NULL)
0N/A return vmSymbols::NO_SID; // regardless of name, no intrinsics here
85N/A
85N/A // see if the klass name is well-known:
85N/A symbolOop klass_name = instanceKlass::cast(holder)->name();
85N/A return vmSymbols::find_sid(klass_name);
85N/A}
85N/A
85N/Avoid methodOopDesc::init_intrinsic_id() {
85N/A assert(_intrinsic_id == vmIntrinsics::_none, "do this just once");
85N/A const uintptr_t max_id_uint = right_n_bits((int)(sizeof(_intrinsic_id) * BitsPerByte));
85N/A assert((uintptr_t)vmIntrinsics::ID_LIMIT <= max_id_uint, "else fix size");
85N/A assert(intrinsic_id_size_in_bytes() == sizeof(_intrinsic_id), "");
85N/A
85N/A // the klass name is well-known:
85N/A vmSymbols::SID klass_id = klass_id_for_intrinsics(method_holder());
85N/A assert(klass_id != vmSymbols::NO_SID, "caller responsibility");
85N/A
85N/A // ditto for method and signature:
85N/A vmSymbols::SID name_id = vmSymbols::find_sid(name());
85N/A if (name_id == vmSymbols::NO_SID) return;
85N/A vmSymbols::SID sig_id = vmSymbols::find_sid(signature());
85N/A if (klass_id != vmSymbols::VM_SYMBOL_ENUM_NAME(java_dyn_MethodHandle)
85N/A && sig_id == vmSymbols::NO_SID) return;
193N/A jshort flags = access_flags().as_short();
193N/A
193N/A vmIntrinsics::ID id = vmIntrinsics::find_id(klass_id, name_id, sig_id, flags);
85N/A if (id != vmIntrinsics::_none) {
85N/A set_intrinsic_id(id);
85N/A return;
85N/A }
155N/A
155N/A // A few slightly irregular cases:
155N/A switch (klass_id) {
85N/A case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_StrictMath):
193N/A // Second chance: check in regular Math.
193N/A switch (name_id) {
85N/A case vmSymbols::VM_SYMBOL_ENUM_NAME(min_name):
163N/A case vmSymbols::VM_SYMBOL_ENUM_NAME(max_name):
193N/A case vmSymbols::VM_SYMBOL_ENUM_NAME(sqrt_name):
193N/A // pretend it is the corresponding method in the non-strict class:
193N/A klass_id = vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_Math);
193N/A id = vmIntrinsics::find_id(klass_id, name_id, sig_id, flags);
193N/A break;
193N/A }
193N/A break;
193N/A
193N/A // Signature-polymorphic methods: MethodHandle.invoke*, InvokeDynamic.*.
193N/A case vmSymbols::VM_SYMBOL_ENUM_NAME(java_dyn_MethodHandle):
85N/A if (is_static() || !is_native()) break;
85N/A switch (name_id) {
85N/A case vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name):
193N/A id = vmIntrinsics::_invokeGeneric;
193N/A break;
193N/A case vmSymbols::VM_SYMBOL_ENUM_NAME(invokeExact_name):
163N/A id = vmIntrinsics::_invokeExact;
85N/A break;
85N/A case vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name):
193N/A if (AllowTransitionalJSR292) id = vmIntrinsics::_invokeExact;
155N/A break;
163N/A }
85N/A break;
163N/A case vmSymbols::VM_SYMBOL_ENUM_NAME(java_dyn_InvokeDynamic):
193N/A if (!is_static() || !is_native()) break;
193N/A id = vmIntrinsics::_invokeDynamic;
193N/A break;
193N/A }
163N/A
193N/A if (id != vmIntrinsics::_none) {
193N/A // Set up its iid. It is an alias method.
193N/A set_intrinsic_id(id);
193N/A return;
193N/A }
193N/A}
163N/A
193N/A// These two methods are static since a GC may move the methodOopDesc
193N/Abool methodOopDesc::load_signature_classes(methodHandle m, TRAPS) {
193N/A bool sig_is_loaded = true;
193N/A Handle class_loader(THREAD, instanceKlass::cast(m->method_holder())->class_loader());
193N/A Handle protection_domain(THREAD, Klass::cast(m->method_holder())->protection_domain());
163N/A symbolHandle signature(THREAD, m->signature());
193N/A for(SignatureStream ss(signature); !ss.is_done(); ss.next()) {
193N/A if (ss.is_object()) {
193N/A symbolOop sym = ss.as_symbol(CHECK_(false));
163N/A symbolHandle name (THREAD, sym);
85N/A klassOop klass = SystemDictionary::resolve_or_null(name, class_loader,
163N/A protection_domain, THREAD);
193N/A // We are loading classes eagerly. If a ClassNotFoundException or
193N/A // a LinkageError was generated, be sure to ignore it.
193N/A if (HAS_PENDING_EXCEPTION) {
193N/A if (PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass()) ||
193N/A PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
193N/A CLEAR_PENDING_EXCEPTION;
193N/A } else {
193N/A return false;
193N/A }
193N/A }
193N/A if( klass == NULL) { sig_is_loaded = false; }
193N/A }
193N/A }
85N/A return sig_is_loaded;
193N/A}
193N/A
193N/Abool methodOopDesc::has_unloaded_classes_in_signature(methodHandle m, TRAPS) {
193N/A Handle class_loader(THREAD, instanceKlass::cast(m->method_holder())->class_loader());
193N/A Handle protection_domain(THREAD, Klass::cast(m->method_holder())->protection_domain());
85N/A symbolHandle signature(THREAD, m->signature());
85N/A for(SignatureStream ss(signature); !ss.is_done(); ss.next()) {
85N/A if (ss.type() == T_OBJECT) {
193N/A symbolHandle name(THREAD, ss.as_symbol_or_null());
193N/A if (name() == NULL) return true;
193N/A klassOop klass = SystemDictionary::find(name, class_loader, protection_domain, THREAD);
193N/A if (klass == NULL) return true;
193N/A }
193N/A }
193N/A return false;
193N/A}
193N/A
193N/A// Exposed so field engineers can debug VM
193N/Avoid methodOopDesc::print_short_name(outputStream* st) {
193N/A ResourceMark rm;
163N/A#ifdef PRODUCT
85N/A st->print(" %s::", method_holder()->klass_part()->external_name());
193N/A#else
193N/A st->print(" %s::", method_holder()->klass_part()->internal_name());
193N/A#endif
85N/A name()->print_symbol_on(st);
193N/A if (WizardMode) signature()->print_symbol_on(st);
193N/A}
193N/A
193N/A
193N/Aextern "C" {
193N/A static int method_compare(methodOop* a, methodOop* b) {
193N/A return (*a)->name()->fast_compare((*b)->name());
163N/A }
163N/A
193N/A // Prevent qsort from reordering a previous valid sort by
163N/A // considering the address of the methodOops if two methods
85N/A // would otherwise compare as equal. Required to preserve
85N/A // optimal access order in the shared archive. Slower than
193N/A // method_compare, only used for shared archive creation.
193N/A static int method_compare_idempotent(methodOop* a, methodOop* b) {
193N/A int i = method_compare(a, b);
193N/A if (i != 0) return i;
85N/A return ( a < b ? -1 : (a == b ? 0 : 1));
85N/A }
0N/A
0N/A // We implement special compare versions for narrow oops to avoid
0N/A // testing for UseCompressedOops on every comparison.
0N/A static int method_compare_narrow(narrowOop* a, narrowOop* b) {
0N/A methodOop m = (methodOop)oopDesc::load_decode_heap_oop(a);
305N/A methodOop n = (methodOop)oopDesc::load_decode_heap_oop(b);
0N/A return m->name()->fast_compare(n->name());
305N/A }
0N/A
0N/A static int method_compare_narrow_idempotent(narrowOop* a, narrowOop* b) {
0N/A int i = method_compare_narrow(a, b);
0N/A if (i != 0) return i;
0N/A return ( a < b ? -1 : (a == b ? 0 : 1));
0N/A }
0N/A
0N/A typedef int (*compareFn)(const void*, const void*);
0N/A}
0N/A
0N/A
0N/A// This is only done during class loading, so it is OK to assume method_idnum matches the methods() array
0N/Astatic void reorder_based_on_method_index(objArrayOop methods,
0N/A objArrayOop annotations,
0N/A GrowableArray<oop>* temp_array) {
0N/A if (annotations == NULL) {
0N/A return;
0N/A }
1409N/A
0N/A int length = methods->length();
0N/A int i;
0N/A // Copy to temp array
0N/A temp_array->clear();
0N/A for (i = 0; i < length; i++) {
0N/A temp_array->append(annotations->obj_at(i));
0N/A }
0N/A
0N/A // Copy back using old method indices
0N/A for (i = 0; i < length; i++) {
0N/A methodOop m = (methodOop) methods->obj_at(i);
0N/A annotations->obj_at_put(i, temp_array->at(m->method_idnum()));
0N/A }
0N/A}
0N/A
0N/A
0N/A// This is only done during class loading, so it is OK to assume method_idnum matches the methods() array
0N/Avoid methodOopDesc::sort_methods(objArrayOop methods,
0N/A objArrayOop methods_annotations,
0N/A objArrayOop methods_parameter_annotations,
0N/A objArrayOop methods_default_annotations,
0N/A bool idempotent) {
0N/A int length = methods->length();
0N/A if (length > 1) {
0N/A bool do_annotations = false;
0N/A if (methods_annotations != NULL ||
0N/A methods_parameter_annotations != NULL ||
0N/A methods_default_annotations != NULL) {
0N/A do_annotations = true;
0N/A }
0N/A if (do_annotations) {
0N/A // Remember current method ordering so we can reorder annotations
0N/A for (int i = 0; i < length; i++) {
0N/A methodOop m = (methodOop) methods->obj_at(i);
0N/A m->set_method_idnum(i);
0N/A }
0N/A }
0N/A
0N/A // Use a simple bubble sort for small number of methods since
0N/A // qsort requires a functional pointer call for each comparison.
0N/A if (length < 8) {
0N/A bool sorted = true;
0N/A for (int i=length-1; i>0; i--) {
305N/A for (int j=0; j<i; j++) {
0N/A methodOop m1 = (methodOop)methods->obj_at(j);
0N/A methodOop m2 = (methodOop)methods->obj_at(j+1);
0N/A if ((uintptr_t)m1->name() > (uintptr_t)m2->name()) {
0N/A methods->obj_at_put(j, m2);
0N/A methods->obj_at_put(j+1, m1);
0N/A sorted = false;
0N/A }
0N/A }
0N/A if (sorted) break;
305N/A sorted = true;
305N/A }
0N/A } else {
0N/A compareFn compare =
0N/A (UseCompressedOops ?
0N/A (compareFn) (idempotent ? method_compare_narrow_idempotent : method_compare_narrow):
0N/A (compareFn) (idempotent ? method_compare_idempotent : method_compare));
0N/A qsort(methods->base(), length, heapOopSize, compare);
0N/A }
0N/A
0N/A // Sort annotations if necessary
0N/A assert(methods_annotations == NULL || methods_annotations->length() == methods->length(), "");
0N/A assert(methods_parameter_annotations == NULL || methods_parameter_annotations->length() == methods->length(), "");
0N/A assert(methods_default_annotations == NULL || methods_default_annotations->length() == methods->length(), "");
0N/A if (do_annotations) {
0N/A ResourceMark rm;
0N/A // Allocate temporary storage
0N/A GrowableArray<oop>* temp_array = new GrowableArray<oop>(length);
0N/A reorder_based_on_method_index(methods, methods_annotations, temp_array);
0N/A reorder_based_on_method_index(methods, methods_parameter_annotations, temp_array);
0N/A reorder_based_on_method_index(methods, methods_default_annotations, temp_array);
0N/A }
0N/A
0N/A // Reset method ordering
0N/A for (int i = 0; i < length; i++) {
0N/A methodOop m = (methodOop) methods->obj_at(i);
0N/A m->set_method_idnum(i);
0N/A }
0N/A }
0N/A}
0N/A
0N/A
0N/A//-----------------------------------------------------------------------------------
0N/A// Non-product code
0N/A
0N/A#ifndef PRODUCT
0N/Aclass SignatureTypePrinter : public SignatureTypeNames {
0N/A private:
0N/A outputStream* _st;
0N/A bool _use_separator;
0N/A
0N/A void type_name(const char* name) {
0N/A if (_use_separator) _st->print(", ");
0N/A _st->print(name);
0N/A _use_separator = true;
0N/A }
0N/A
0N/A public:
0N/A SignatureTypePrinter(symbolHandle signature, outputStream* st) : SignatureTypeNames(signature) {
0N/A _st = st;
0N/A _use_separator = false;
0N/A }
0N/A
0N/A void print_parameters() { _use_separator = false; iterate_parameters(); }
0N/A void print_returntype() { _use_separator = false; iterate_returntype(); }
0N/A};
0N/A
0N/A
0N/Avoid methodOopDesc::print_name(outputStream* st) {
0N/A Thread *thread = Thread::current();
0N/A ResourceMark rm(thread);
0N/A SignatureTypePrinter sig(signature(), st);
0N/A st->print("%s ", is_static() ? "static" : "virtual");
0N/A sig.print_returntype();
0N/A st->print(" %s.", method_holder()->klass_part()->internal_name());
0N/A name()->print_symbol_on(st);
0N/A st->print("(");
0N/A sig.print_parameters();
0N/A st->print(")");
0N/A}
0N/A
113N/A
113N/Avoid methodOopDesc::print_codes_on(outputStream* st) const {
113N/A print_codes_on(0, code_size(), st);
113N/A}
113N/A
113N/Avoid methodOopDesc::print_codes_on(int from, int to, outputStream* st) const {
0N/A Thread *thread = Thread::current();
0N/A ResourceMark rm(thread);
0N/A methodHandle mh (thread, (methodOop)this);
0N/A BytecodeStream s(mh);
0N/A s.set_interval(from, to);
0N/A BytecodeTracer::set_closure(BytecodeTracer::std_closure());
0N/A while (s.next() >= 0) BytecodeTracer::trace(mh, s.bcp(), st);
0N/A}
0N/A#endif // not PRODUCT
0N/A
0N/A
0N/A// Simple compression of line number tables. We use a regular compressed stream, except that we compress deltas
0N/A// between (bci,line) pairs since they are smaller. If (bci delta, line delta) fits in (5-bit unsigned, 3-bit unsigned)
0N/A// we save it as one byte, otherwise we write a 0xFF escape character and use regular compression. 0x0 is used
0N/A// as end-of-stream terminator.
0N/A
0N/Avoid CompressedLineNumberWriteStream::write_pair_regular(int bci_delta, int line_delta) {
0N/A // bci and line number does not compress into single byte.
0N/A // Write out escape character and use regular compression for bci and line number.
0N/A write_byte((jubyte)0xFF);
0N/A write_signed_int(bci_delta);
0N/A write_signed_int(line_delta);
0N/A}
0N/A
0N/A// See comment in methodOop.hpp which explains why this exists.
0N/A#if defined(_M_AMD64) && MSC_VER >= 1400
0N/A#pragma optimize("", off)
0N/Avoid CompressedLineNumberWriteStream::write_pair(int bci, int line) {
0N/A write_pair_inline(bci, line);
0N/A}
0N/A#pragma optimize("", on)
0N/A#endif
0N/A
0N/ACompressedLineNumberReadStream::CompressedLineNumberReadStream(u_char* buffer) : CompressedReadStream(buffer) {
0N/A _bci = 0;
0N/A _line = 0;
0N/A};
0N/A
0N/A
0N/Abool CompressedLineNumberReadStream::read_pair() {
0N/A jubyte next = read_byte();
2250N/A // Check for terminator
2250N/A if (next == 0) return false;
0N/A if (next == 0xFF) {
0N/A // Escape character, regular compression used
2250N/A _bci += read_signed_int();
2250N/A _line += read_signed_int();
0N/A } else {
0N/A // Single byte compression used
0N/A _bci += next >> 3;
0N/A _line += next & 0x7;
0N/A }
0N/A return true;
0N/A}
0N/A
0N/A
0N/ABytecodes::Code methodOopDesc::orig_bytecode_at(int bci) {
0N/A BreakpointInfo* bp = instanceKlass::cast(method_holder())->breakpoints();
2250N/A for (; bp != NULL; bp = bp->next()) {
0N/A if (bp->match(this, bci)) {
0N/A return bp->orig_bytecode();
0N/A }
0N/A }
2250N/A ShouldNotReachHere();
0N/A return Bytecodes::_shouldnotreachhere;
0N/A}
0N/A
2250N/Avoid methodOopDesc::set_orig_bytecode_at(int bci, Bytecodes::Code code) {
2250N/A assert(code != Bytecodes::_breakpoint, "cannot patch breakpoints this way");
2250N/A BreakpointInfo* bp = instanceKlass::cast(method_holder())->breakpoints();
2250N/A for (; bp != NULL; bp = bp->next()) {
2250N/A if (bp->match(this, bci)) {
2250N/A bp->set_orig_bytecode(code);
2250N/A // and continue, in case there is more than one
2250N/A }
0N/A }
0N/A}
0N/A
0N/Avoid methodOopDesc::set_breakpoint(int bci) {
0N/A instanceKlass* ik = instanceKlass::cast(method_holder());
0N/A BreakpointInfo *bp = new BreakpointInfo(this, bci);
0N/A bp->set_next(ik->breakpoints());
0N/A ik->set_breakpoints(bp);
0N/A // do this last:
0N/A bp->set(this);
0N/A}
0N/A
0N/Astatic void clear_matches(methodOop m, int bci) {
0N/A instanceKlass* ik = instanceKlass::cast(m->method_holder());
2250N/A BreakpointInfo* prev_bp = NULL;
0N/A BreakpointInfo* next_bp;
0N/A for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = next_bp) {
0N/A next_bp = bp->next();
0N/A // bci value of -1 is used to delete all breakpoints in method m (ex: clear_all_breakpoint).
0N/A if (bci >= 0 ? bp->match(m, bci) : bp->match(m)) {
0N/A // do this first:
0N/A bp->clear(m);
0N/A // unhook it
0N/A if (prev_bp != NULL)
2250N/A prev_bp->set_next(next_bp);
0N/A else
0N/A ik->set_breakpoints(next_bp);
0N/A delete bp;
0N/A // When class is redefined JVMTI sets breakpoint in all versions of EMCP methods
0N/A // at same location. So we have multiple matching (method_index and bci)
0N/A // BreakpointInfo nodes in BreakpointInfo list. We should just delete one
0N/A // breakpoint for clear_breakpoint request and keep all other method versions
0N/A // BreakpointInfo for future clear_breakpoint request.
0N/A // bcivalue of -1 is used to clear all breakpoints (see clear_all_breakpoints)
0N/A // which is being called when class is unloaded. We delete all the Breakpoint
0N/A // information for all versions of method. We may not correctly restore the original
0N/A // bytecode in all method versions, but that is ok. Because the class is being unloaded
0N/A // so these methods won't be used anymore.
0N/A if (bci >= 0) {
0N/A break;
0N/A }
0N/A } else {
0N/A // This one is a keeper.
0N/A prev_bp = bp;
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid methodOopDesc::clear_breakpoint(int bci) {
0N/A assert(bci >= 0, "");
0N/A clear_matches(this, bci);
0N/A}
0N/A
0N/Avoid methodOopDesc::clear_all_breakpoints() {
0N/A clear_matches(this, -1);
0N/A}
0N/A
0N/A
0N/Aint methodOopDesc::invocation_count() {
0N/A if (TieredCompilation) {
0N/A const methodDataOop mdo = method_data();
0N/A if (invocation_counter()->carry() || ((mdo != NULL) ? mdo->invocation_counter()->carry() : false)) {
0N/A return InvocationCounter::count_limit;
0N/A } else {
0N/A return invocation_counter()->count() + ((mdo != NULL) ? mdo->invocation_counter()->count() : 0);
0N/A }
0N/A } else {
0N/A return invocation_counter()->count();
0N/A }
0N/A}
0N/A
0N/Aint methodOopDesc::backedge_count() {
0N/A if (TieredCompilation) {
0N/A const methodDataOop mdo = method_data();
0N/A if (backedge_counter()->carry() || ((mdo != NULL) ? mdo->backedge_counter()->carry() : false)) {
0N/A return InvocationCounter::count_limit;
0N/A } else {
0N/A return backedge_counter()->count() + ((mdo != NULL) ? mdo->backedge_counter()->count() : 0);
0N/A }
0N/A } else {
0N/A return backedge_counter()->count();
0N/A }
0N/A}
0N/A
0N/Aint methodOopDesc::highest_comp_level() const {
0N/A methodDataOop mdo = method_data();
0N/A if (mdo != NULL) {
0N/A return mdo->highest_comp_level();
0N/A } else {
0N/A return CompLevel_none;
0N/A }
0N/A}
0N/A
0N/Aint methodOopDesc::highest_osr_comp_level() const {
0N/A methodDataOop mdo = method_data();
0N/A if (mdo != NULL) {
0N/A return mdo->highest_osr_comp_level();
0N/A } else {
0N/A return CompLevel_none;
0N/A }
0N/A}
0N/A
0N/Avoid methodOopDesc::set_highest_comp_level(int level) {
0N/A methodDataOop mdo = method_data();
0N/A if (mdo != NULL) {
0N/A mdo->set_highest_comp_level(level);
0N/A }
0N/A}
0N/A
0N/Avoid methodOopDesc::set_highest_osr_comp_level(int level) {
0N/A methodDataOop mdo = method_data();
0N/A if (mdo != NULL) {
0N/A mdo->set_highest_osr_comp_level(level);
0N/A }
0N/A}
0N/A
0N/ABreakpointInfo::BreakpointInfo(methodOop m, int bci) {
0N/A _bci = bci;
0N/A _name_index = m->name_index();
0N/A _signature_index = m->signature_index();
0N/A _orig_bytecode = (Bytecodes::Code) *m->bcp_from(_bci);
0N/A if (_orig_bytecode == Bytecodes::_breakpoint)
0N/A _orig_bytecode = m->orig_bytecode_at(_bci);
0N/A _next = NULL;
0N/A}
0N/A
0N/Avoid BreakpointInfo::set(methodOop method) {
0N/A#ifdef ASSERT
0N/A {
0N/A Bytecodes::Code code = (Bytecodes::Code) *method->bcp_from(_bci);
0N/A if (code == Bytecodes::_breakpoint)
0N/A code = method->orig_bytecode_at(_bci);
0N/A assert(orig_bytecode() == code, "original bytecode must be the same");
0N/A }
0N/A#endif
0N/A *method->bcp_from(_bci) = Bytecodes::_breakpoint;
0N/A method->incr_number_of_breakpoints();
0N/A SystemDictionary::notice_modification();
0N/A {
0N/A // Deoptimize all dependents on this method
0N/A Thread *thread = Thread::current();
0N/A HandleMark hm(thread);
0N/A methodHandle mh(thread, method);
0N/A Universe::flush_dependents_on_method(mh);
0N/A }
0N/A}
0N/A
0N/Avoid BreakpointInfo::clear(methodOop method) {
0N/A *method->bcp_from(_bci) = orig_bytecode();
0N/A assert(method->number_of_breakpoints() > 0, "must not go negative");
0N/A method->decr_number_of_breakpoints();
0N/A}
0N/A