rewriter.cpp revision 726
579N/A * Copyright 1998-2009 Sun Microsystems, Inc. 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. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A#
include "incls/_precompiled.incl" 726N/A// Computes a CPC map (new_index -> original_index) for constant pool entries 0N/A// that are referred to by the interpreter at runtime via the constant pool cache. 726N/A// Also computes a CP map (original_index -> new_index). 726N/A// Marks entries in CP which require additional processing. 726N/A "all cp cache indexes fit in a u2");
726N/A // Hack: We put it on the map as an encoded value. 726N/A // The only place that consumes this is ConstantPoolCacheEntry::set_initial_state 726N/A// Creates a constant pool cache given a CPC map 542N/A// This creates the constant pool cache initially in a state 542N/A// that is unsafe for concurrent GC processing but sets it to 542N/A// a safe mode before the constant pool cache is returned. 0N/A// The new finalization semantics says that registration of 0N/A// finalizable objects must be performed on successful return from the 0N/A// Object.<init> constructor. We could implement this trivially if 0N/A// <init> were never rewritten but since JVMTI allows this to occur, a 0N/A// more complicated solution is required. A special return bytecode 0N/A// is used only by Object.<init> to signal the finalization 0N/A// registration point. Additionally local 0 must be preserved so it's 0N/A// available to pass to the registration function. For simplicty we 0N/A// require that local 0 is never overwritten so it's available as an 0N/A// argument for registration. 0N/A "can't overwrite local 0 in Object.<init>");
726N/A// Rewrite a classfile-order CP index into a native-order CPC index. 726N/A // Replace the trailing four bytes with a CPC index for the dynamic 726N/A // call site. Unlike other CPC entries, there is one per bytecode, 726N/A // not just one per distinct CP entry. In other words, the 726N/A // CPC-to-CP relation is many-to-one for invokedynamic entries. 726N/A // This means we must use a larger index size than u2 to address 726N/A // all these entries. That is the main reason invokedynamic 726N/A // must have a five-byte instruction format. (Of course, other JVM 726N/A // implementations can use the bytes for other purposes.) 726N/A // Note: We use native_u4 format exclusively for 4-byte indexes. 0N/A// Rewrites a method given the index_map information 0N/A // We cannot tolerate a GC in this block, because we've 0N/A // cached the bytecodes in 'code_base'. If the methodOop 0N/A // moves, the bytecodes will also move. 0N/A // Bytecodes and their length 0N/A // Since we have the code, see if we can get the length 0N/A // directly. Some more complicated bytecodes will report 0N/A // a length of zero, meaning we need to make another method 0N/A // call to calculate the length. 0N/A // length_at will put us at the bytecode after the one modified 0N/A // by 'wide'. We don't currently examine any of the bytecodes 0N/A // modified by wide, but in case we do in the future... 0N/A // Update access flags 0N/A // The present of a jsr bytecode implies that the method might potentially 0N/A // have to be rewritten, so we run the oopMapGenerator on the method 726N/A // Second pass will revisit this method. 726N/A// After constant pool is created, revisit methods containing jsrs. 726N/A // Insert invalid bytecode into original methodOop and set 726N/A // interpreter entrypoint, so that a executing this method 726N/A // will manifest itself in an easy recognizable form. 726N/A // Update monitor matching info. 726N/A // (That's all, folks.) 726N/A // gather starting points 0N/A // determine index maps for methodOop rewriting 0N/A // rewrite the return bytecodes of Object.<init> to register the 0N/A // object for finalization if needed. 726N/A // rewrite methods, in two passes 726N/A // allocate constant pool cache, now that we've seen all the bytecodes 0N/A // Method might have gotten rewritten. 726N/A // Set up method entry points for compiler and interpreter.