methodOop.cpp revision 1879
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 * 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// Implementation of methodOopDesc 0N/A // exception table holds quadruple entries of the form (beg_bci, end_bci, handler_bci, klass_index) 0N/A // access exception table 0N/A // iterate through all entries sequentially 0N/A // exception handler bci range covers throw_bci => investigate further 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 // TO DO: this may be unsafe in some configurations 0N/A // verify stack calls this outside VM thread 0N/A "VM, GC task or CMS threads (or during debugging)");
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/A // keep bci as -1 if not a valid bci 0N/A // code_size() may return 0 and we allow 0 here 0N/A // the method may be native 0N/A // Assert that if we have dodged any asserts, bci is negative. 0N/A // If native, then include pointers for native_function and signature_handler 0N/A "interpreter entry must be valid");
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 // 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 // interpreter doesn't bump invocation counter of trivial methods 0N/A // compiler does not bump invocation counter of compiled methods 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 // dump the size of the byte codes 0N/A// Build a methodDataOop object to hold information about this method 0N/A// collected in the interpreter. 0N/A // Grab a lock here to prevent multiple 0N/A // methodDataOops from being created. 0N/A // At the end of the run, the MDO, full of data, will be dumped. 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 // not an inline function, to avoid a header dependency on Interpreter 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 // followed by an (optional) sequence of: 0N/A // aconst_null / iconst_0 / fconst_0 / dconst_0 0N/A // Check if size match 0N/A // Does not call superclass default constructor 0N/A // Check optional sequence 0N/A for (
int i =
4; i <
last; i +=
5) {
0N/A // %%% Should return true for private methods also, 0N/A // since there is no way to override them. 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 // Make sure klass is resolved in constantpool. 0N/A // We can see racers trying to place the same native function into place. Once 0N/A // native_method_throw_unsatisfied_link_error_entry() should only 0N/A // be passed when post_event_flag is false. 0N/A "post_event_flag mis-match");
0N/A // post the bind event, and possible change the bind 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 // compilers must recognize this method specially, or not at all 0N/A// call this when compiler finds that this method is not compilable 0N/A// Revert to using the interpreter and clear out the nmethod 0N/A // this may be NULL if c2i adapters have not been made yet 0N/A // Only should happen at allocate time. 0N/A// Called by class data sharing to remove any entry points (which are not shared) 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/A // Setup interpreter entrypoint 0N/A // Sets both _i2i_entry and _from_interpreted_entry 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 // ONLY USE the h_method now as make_adapter may have blocked 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// The verified_code_entry() must be called when a invoke is resolved 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/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/A // cached in a register or local. There's a race on the value of the field. 0N/A// Install compiled code. Instantly it can execute. 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 // In theory there could be a race here. In practice it is unlikely 0N/A // and not worth worrying about. 0N/A // Instantly compiled code can execute. 0N/A // If method is an interface, we skip it - except if it 0N/A // is a miranda method 0N/A // Check that method is not a miranda method 0N/A // No implementation exist - so miranda method 0N/A// give advice about whether this methodOop should be cached or not 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. 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 // caching this method should be just fine 0N/A// Constant pool structure for invoke methods: 0N/A // do this in reverse to avoid races: 0N/A//------------------------------------------------------------------------------ 0N/A// methodOopDesc::is_method_handle_adapter 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/A "must be a JSR 292 magic type");
0N/A // set up the fancy stuff: 0N/A // Finally, set up its entry points. 0N/A // Make sure the pointer chase works. 0N/A // Code below does not work for native methods - they should never get rewritten anyway 0N/A // Allocate new methodOop 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 // Create a shallow copy of methodOopDesc part, but be careful to preserve the new constMethodOop 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. 0N/A // Copy new byte codes 0N/A // Copy line number table 0N/A // Copy checked_exceptions 0N/A // Copy local variable number table 0N/A // Only set is_conc_safe to true when changes to newcm are 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 85N/A // see if the klass name is well-known: 85N/A // the klass name is well-known: 85N/A // ditto for method and signature: 155N/A // A few slightly irregular cases: 193N/A // Second chance: check in regular Math. 193N/A // pretend it is the corresponding method in the non-strict class: 193N/A // Signature-polymorphic methods: MethodHandle.invoke*, InvokeDynamic.*. 193N/A // Set up its iid. It is an alias method. 193N/A// These two methods are static since a GC may move the methodOopDesc 193N/A // We are loading classes eagerly. If a ClassNotFoundException or 193N/A // a LinkageError was generated, be sure to ignore it. 193N/A// Exposed so field engineers can debug VM 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. 85N/A return ( a < b ? -
1 : (a == b ? 0 :
1));
0N/A // We implement special compare versions for narrow oops to avoid 0N/A // testing for UseCompressedOops on every comparison. 0N/A if (i != 0)
return i;
0N/A return ( a < b ? -
1 : (a == b ? 0 :
1));
0N/A// This is only done during class loading, so it is OK to assume method_idnum matches the methods() array 0N/A // Copy to temp array 0N/A // Copy back using old method indices 0N/A// This is only done during class loading, so it is OK to assume method_idnum matches the methods() array 0N/A // Remember current method ordering so we can reorder annotations 0N/A // Use a simple bubble sort for small number of methods since 0N/A // qsort requires a functional pointer call for each comparison. 305N/A for (
int j=0; j<i; j++) {
0N/A // Sort annotations if necessary 0N/A // Allocate temporary storage 0N/A // Reset method ordering 0N/A//----------------------------------------------------------------------------------- 0N/A#
endif // not PRODUCT 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 // 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 // Escape character, regular compression used 0N/A // Single byte compression used 2250N/A // and continue, in case there is more than one 0N/A // bci value of -1 is used to delete all breakpoints in method m (ex: clear_all_breakpoint). 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 // This one is a keeper. 0N/A // Deoptimize all dependents on this method