rewriter.cpp revision 1059
3349N/A * Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved. 3349N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3349N/A * This code is free software; you can redistribute it and/or modify it 3349N/A * under the terms of the GNU General Public License version 2 only, as 3349N/A * published by the Free Software Foundation. 3349N/A * This code is distributed in the hope that it will be useful, but WITHOUT 3349N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3349N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3349N/A * version 2 for more details (a copy is included in the LICENSE file that 3349N/A * You should have received a copy of the GNU General Public License version 3349N/A * 2 along with this work; if not, write to the Free Software Foundation, 3349N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3349N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 3349N/A * CA 95054 USA or visit www.sun.com if you need additional information or 3349N/A#
include "incls/_precompiled.incl" 3349N/A// Computes a CPC map (new_index -> original_index) for constant pool entries 3349N/A// that are referred to by the interpreter at runtime via the constant pool cache. 3349N/A// Also computes a CP map (original_index -> new_index). 3349N/A// Marks entries in CP which require additional processing. 3349N/A "all cp cache indexes fit in a u2");
3349N/A// Creates a constant pool cache given a CPC map 3349N/A// This creates the constant pool cache initially in a state 3349N/A// that is unsafe for concurrent GC processing but sets it to 3349N/A// a safe mode before the constant pool cache is returned. 3349N/A// The new finalization semantics says that registration of 3349N/A// finalizable objects must be performed on successful return from the 3349N/A// Object.<init> constructor. We could implement this trivially if 3349N/A// <init> were never rewritten but since JVMTI allows this to occur, a 3349N/A// more complicated solution is required. A special return bytecode 3349N/A// is used only by Object.<init> to signal the finalization 3349N/A// registration point. Additionally local 0 must be preserved so it's 3349N/A// available to pass to the registration function. For simplicty we 3349N/A// require that local 0 is never overwritten so it's available as an 3349N/A// argument for registration. 3349N/A "can't overwrite local 0 in Object.<init>");
3349N/A// Rewrite a classfile-order CP index into a native-order CPC index. 3349N/A // Replace the trailing four bytes with a CPC index for the dynamic 3349N/A // call site. Unlike other CPC entries, there is one per bytecode, 3349N/A // not just one per distinct CP entry. In other words, the 3349N/A // CPC-to-CP relation is many-to-one for invokedynamic entries. 3349N/A // This means we must use a larger index size than u2 to address 3349N/A // all these entries. That is the main reason invokedynamic 3349N/A // must have a five-byte instruction format. (Of course, other JVM 3349N/A // implementations can use the bytes for other purposes.) 3349N/A // Note: We use native_u4 format exclusively for 4-byte indexes. 3349N/A// Rewrites a method given the index_map information 3349N/A // We cannot tolerate a GC in this block, because we've 3349N/A // cached the bytecodes in 'code_base'. If the methodOop 3349N/A // moves, the bytecodes will also move. 3349N/A // Bytecodes and their length 3349N/A // Since we have the code, see if we can get the length 3349N/A // directly. Some more complicated bytecodes will report 3349N/A // a length of zero, meaning we need to make another method 3349N/A // call to calculate the length. 3349N/A // length_at will put us at the bytecode after the one modified 3349N/A // by 'wide'. We don't currently examine any of the bytecodes 3349N/A // modified by wide, but in case we do in the future... 3349N/A // The present of a jsr bytecode implies that the method might potentially 3349N/A // have to be rewritten, so we run the oopMapGenerator on the method 3349N/A // Second pass will revisit this method. 3349N/A// After constant pool is created, revisit methods containing jsrs. 3349N/A // Insert invalid bytecode into original methodOop and set 3349N/A // interpreter entrypoint, so that a executing this method 3349N/A // will manifest itself in an easy recognizable form. 3349N/A // Update monitor matching info. 3349N/A // determine index maps for methodOop rewriting 3349N/A // rewrite the return bytecodes of Object.<init> to register the 3349N/A // object for finalization if needed. 3349N/A // rewrite methods, in two passes 3349N/A // allocate constant pool cache, now that we've seen all the bytecodes 3349N/A // Method might have gotten rewritten. 3349N/A // Set up method entry points for compiler and interpreter.