methodOop.cpp revision 1472
1472N/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 * 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 * 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 * 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. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A#
include "incls/_precompiled.incl" 0N/A// Implementation of methodOopDesc // exception table holds quadruple entries of the form (beg_bci, end_bci, handler_bci, klass_index) // access exception table // iterate through all entries sequentially // exception handler bci range covers throw_bci => investigate further // we know the exception class => get the constraint class // this may require loading of the constraint class; if verification // fails or some other exception occurs, return handler_bci // TO DO: this may be unsafe in some configurations // verify stack calls this outside VM thread warning(
"oopmap should only be accessed by the " "VM, GC task or CMS threads (or during debugging)");
// Return (int)bcx if it appears to be a valid BCI. // Return bci_from((address)bcx) if it appears to be a valid BCP. // Used by profiling code, when invalid data is a possibility. // The caller is responsible for validating the methodOop itself. // keep bci as -1 if not a valid bci // code_size() may return 0 and we allow 0 here // the method may be native // Assert that if we have dodged any asserts, bci is negative. // If native, then include pointers for native_function and signature_handler "interpreter entry must be valid");
// Attempt to return method oop to original state. Clear any pointers // (to objects outside the shared spaces). We won't be able to predict // where they should point in a new JVM. Further initialize some // entries now in order allow them to be write protected later. // Invocation counter is reset when the methodOop is compiled. // If the method has compiled code we therefore assume it has // be excuted more than n times. // interpreter doesn't bump invocation counter of trivial methods // compiler does not bump invocation counter of compiled methods // The carry bit is set when the counter overflows and causes // a compilation to occur. We don't know how many times // the counter has been reset, so we simply assume it has // been executed more than n times. // dump the size of the byte codes // Build a methodDataOop object to hold information about this method // collected in the interpreter. // Grab a lock here to prevent multiple // methodDataOops from being created. tty->
print(
"build_interpreter_method_data for ");
// At the end of the run, the MDO, full of data, will be dumped. // The current system doesn't use inline caches in the interpreter // => nothing to do (keep this method around for future use) // not an inline function, to avoid a header dependency on Interpreter // Returns true if this method is a vanilla constructor, i.e. an "<init>" "()V" method // which only calls the superclass vanilla constructor and possibly does stores of // zero constants to local fields: // followed by an (optional) sequence of: // aconst_null / iconst_0 / fconst_0 / dconst_0 if (
size == 0 ||
size %
5 != 0)
return false;
// Does not call superclass default constructor // Check optional sequence for (
int i =
4; i <
last; i +=
5) {
// %%% Should return true for private methods also, // since there is no way to override them. if (
length == 0) {
// common case for (
int i = 0; i <
length; i++) {
// The line numbers are a short array of 2-tuples [start_pc, line_number]. // Not necessarily sorted and not necessarily one-to-one. // Make sure klass is resolved in constantpool. // We can see racers trying to place the same native function into place. Once // native_method_throw_unsatisfied_link_error_entry() should only // be passed when post_event_flag is false. "post_event_flag mis-match");
// post the bind event, and possible change the bind function // This function can be called more than once. We must make sure that we always // use the latest registered method -> check if a stub already has been generated. // If so, we have to make it not_entrant. nmethod*
nm =
code();
// Put it into local variable to guard against concurrent updates // compilers must recognize this method specially, or not at all // call this when compiler finds that this method is not compilable // Revert to using the interpreter and clear out the nmethod // this may be NULL if c2i adapters have not been made yet // Only should happen at allocate time. // Called by class data sharing to remove any entry points (which are not shared) // Called when the method_holder is getting linked. Setup entrypoints so the method // is ready to be called from interpreter, compiler, and vtables. // Setup interpreter entrypoint // Sets both _i2i_entry and _from_interpreted_entry // Setup compiler entrypoint. This is made eagerly, so we do not need // special handling of vtables. An alternative is to make adapters more // lazily by calling make_adapter() from from_compiled_entry() for the // normal calls. For vtable calls life gets more complicated. When a // call-site goes mega-morphic we need adapters in all methods which can be // called from the vtable. We need adapters on such methods that get loaded // later. Ditto for mega-morphic itable calls. If this proves to be a // problem we'll make these lazily later. // ONLY USE the h_method now as make_adapter may have blocked // Adapters for compiled code are made eagerly here. They are fairly // small (generally < 100 bytes) and quick to make (and cached and shared) // so making them eagerly shouldn't be too expensive. // The verified_code_entry() must be called when a invoke is resolved // It returns the compiled code entry point, after asserting not null. // This function is called after potential safepoints so that nmethod // or adapter that it points to is still live and valid. // This function must not hit a safepoint! // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all // (could be racing a deopt). // Not inline to avoid circular ref. // cached in a register or local. There's a race on the value of the field. // Install compiled code. Instantly it can execute. // These writes must happen in this order, because the interpreter will // directly jump to from_interpreted_entry which jumps to an i2c adapter // which jumps to _from_compiled_entry. mh->
_code =
code;
// Assign before allowing compiled code to exec // In theory there could be a race here. In practice it is unlikely // and not worth worrying about. // Instantly compiled code can execute. // If method is an interface, we skip it - except if it // Check that method is not a miranda method // No implementation exist - so miranda method // give advice about whether this methodOop should be cached or not // This method has been redefined. It is either EMCP or obsolete // and we don't want to cache it because that would pin the method // down and prevent it from being collectible if and when it // It is either not safe or not a good idea to cache this // method at this time because of the state of the embedded // caching this method should be just fine // Constant pool structure for invoke methods: // do this in reverse to avoid races: //------------------------------------------------------------------------------ // methodOopDesc::is_method_handle_adapter // Tests if this method is an internal adapter frame from the // Must be consistent with MethodHandleCompiler::get_method_oop(). "must be a JSR 292 magic type");
tty->
print(
"Creating invoke method for ");
// set up the fancy stuff: // Finally, set up its entry points. // Make sure the pointer chase works. // Code below does not work for native methods - they should never get rewritten anyway // Allocate new methodOop // Allocate newm_oop with the is_conc_safe parameter set // to IsUnsafeConc to indicate that newm_oop is not yet // safe for concurrent processing by a GC. // Create a shallow copy of methodOopDesc part, but be careful to preserve the new constMethodOop // Create shallow copy of constMethodOopDesc, but be careful to preserve the methodOop // is_conc_safe is set to false because that is the value of // is_conc_safe initialzied into newcm and the copy should // not overwrite that value. During the window during which it is // tagged as unsafe, some extra work could be needed during precleaning // or concurrent marking but those phases will be correct. Setting and // resetting is done in preference to a careful copying into newcm to // avoid having to know the precise layout of a constMethodOop. // Reset correct method/const method, method size, and parameter info // Copy line number table // Copy checked_exceptions // Copy local variable number table // Only set is_conc_safe to true when changes to newcm are // if loader is not the default loader (i.e., != NULL), we can't know the intrinsics // because we are not loading from core libraries // see if the klass name is well-known: // the klass name is well-known: // ditto for method and signature: // A few slightly irregular cases: // Second chance: check in regular Math. // pretend it is the corresponding method in the non-strict class: // Signature-polymorphic methods: MethodHandle.invoke*, InvokeDynamic.*. // Set up its iid. It is an alias method. // These two methods are static since a GC may move the methodOopDesc // We are loading classes eagerly. If a ClassNotFoundException or // a LinkageError was generated, be sure to ignore it. // Exposed so field engineers can debug VM // Prevent qsort from reordering a previous valid sort by // considering the address of the methodOops if two methods // would otherwise compare as equal. Required to preserve // optimal access order in the shared archive. Slower than // method_compare, only used for shared archive creation. return ( a < b ? -
1 : (a == b ? 0 :
1));
// We implement special compare versions for narrow oops to avoid // testing for UseCompressedOops on every comparison. return ( a < b ? -
1 : (a == b ? 0 :
1));
typedef int (*
compareFn)(
const void*,
const void*);
// This is only done during class loading, so it is OK to assume method_idnum matches the methods() array for (i = 0; i <
length; i++) {
// Copy back using old method indices for (i = 0; i <
length; i++) {
// This is only done during class loading, so it is OK to assume method_idnum matches the methods() array // Remember current method ordering so we can reorder annotations for (
int i = 0; i <
length; i++) {
// Use a simple bubble sort for small number of methods since // qsort requires a functional pointer call for each comparison. for (
int i=
length-
1; i>0; i--) {
for (
int j=0; j<i; j++) {
// Sort annotations if necessary // Allocate temporary storage for (
int i = 0; i <
length; i++) {
//----------------------------------------------------------------------------------- // Simple compression of line number tables. We use a regular compressed stream, except that we compress deltas // between (bci,line) pairs since they are smaller. If (bci delta, line delta) fits in (5-bit unsigned, 3-bit unsigned) // we save it as one byte, otherwise we write a 0xFF escape character and use regular compression. 0x0 is used // as end-of-stream terminator. // bci and line number does not compress into single byte. // Write out escape character and use regular compression for bci and line number. if (
next == 0)
return false;
// Escape character, regular compression used // Single byte compression used // and continue, in case there is more than one // bci value of -1 is used to delete all breakpoints in method m (ex: clear_all_breakpoint). // When class is redefined JVMTI sets breakpoint in all versions of EMCP methods // at same location. So we have multiple matching (method_index and bci) // BreakpointInfo nodes in BreakpointInfo list. We should just delete one // breakpoint for clear_breakpoint request and keep all other method versions // BreakpointInfo for future clear_breakpoint request. // bcivalue of -1 is used to clear all breakpoints (see clear_all_breakpoints) // which is being called when class is unloaded. We delete all the Breakpoint // information for all versions of method. We may not correctly restore the original // bytecode in all method versions, but that is ok. Because the class is being unloaded // so these methods won't be used anymore. // Deoptimize all dependents on this method