rewriter.cpp revision 579
/*
* Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
# include "incls/_precompiled.incl"
# include "incls/_rewriter.cpp.incl"
// Computes an index_map (new_index -> original_index) for contant pool entries
// that are referred to by the interpreter at runtime via the constant pool cache.
void Rewriter::compute_index_maps(constantPoolHandle pool, intArray*& index_map, intStack*& inverse_index_map) {
// Choose an initial value large enough that we don't get frequent
// calls to grow().
for (int i = 0; i < length; i++) {
case JVM_CONSTANT_Fieldref : // fall through
case JVM_CONSTANT_Methodref : // fall through
case JVM_CONSTANT_InterfaceMethodref: {
inverse_index_map->append(i);
}
}
}
}
// Creates a constant pool cache given an inverse_index_map
// This creates the constant pool cache initially in a state
// that is unsafe for concurrent GC processing but sets it to
// a safe mode before the constant pool cache is returned.
}
// The new finalization semantics says that registration of
// finalizable objects must be performed on successful return from the
// Object.<init> constructor. We could implement this trivially if
// <init> were never rewritten but since JVMTI allows this to occur, a
// more complicated solution is required. A special return bytecode
// is used only by Object.<init> to signal the finalization
// registration point. Additionally local 0 must be preserved so it's
// available to pass to the registration function. For simplicty we
// require that local 0 is never overwritten so it's available as an
// argument for registration.
while (!bcs.is_last_bytecode()) {
switch (opcode) {
// fall through
"can't overwrite local 0 in Object.<init>");
break;
}
}
}
// Rewrites a method given the index_map information
int nof_jsrs = 0;
bool has_monitor_bytecodes = false;
{
// We cannot tolerate a GC in this block, because we've
// cached the bytecodes in 'code_base'. If the methodOop
// moves, the bytecodes will also move.
// Bytecodes and their length
int bc_length;
// Since we have the code, see if we can get the length
// directly. Some more complicated bytecodes will report
// a length of zero, meaning we need to make another method
// call to calculate the length.
if (bc_length == 0) {
// length_at will put us at the bytecode after the one modified
// by 'wide'. We don't currently examine any of the bytecodes
// modified by wide, but in case we do in the future...
}
}
switch (c) {
case Bytecodes::_lookupswitch : {
#ifndef CC_INTERP
);
#endif
break;
}
case Bytecodes::_invokeinterface: {
break;
}
}
}
}
// Update access flags
if (has_monitor_bytecodes) {
}
// The present of a jsr bytecode implies that the method might potentially
// have to be rewritten, so we run the oopMapGenerator on the method
if (nof_jsrs > 0) {
method->set_has_jsrs();
if (method() != original_method()) {
// Insert invalid bytecode into original methodOop and set
// interpreter entrypoint, so that a executing this method
// will manifest itself in an easy recognizable form.
}
// Update monitor matching info.
if (romc.monitor_safe()) {
}
}
// Setup method entrypoints for compiler and interpreter
return method;
}
// gather starting points
// determine index maps for methodOop rewriting
// allocate constant pool cache
while (i-- > 0) {
// rewrite the return bytecodes of Object.<init> to register the
// object for finalization if needed.
rewrite_Object_init(m, CHECK);
break;
}
}
}
// rewrite methods
while (i-- > 0) {
// Method might have gotten rewritten.
methods->obj_at_put(i, m());
}
}
}