2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2015-05-13 15:16:06 +02:00
|
|
|
* Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* 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.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "precompiled.hpp"
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "gc/shared/gcLocker.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "interpreter/bytecodes.hpp"
|
|
|
|
#include "interpreter/interpreter.hpp"
|
|
|
|
#include "interpreter/rewriter.hpp"
|
2015-03-25 15:18:37 -07:00
|
|
|
#include "memory/metaspaceShared.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "memory/resourceArea.hpp"
|
|
|
|
#include "oops/generateOopMap.hpp"
|
2012-07-24 10:51:00 -07:00
|
|
|
#include "prims/methodHandles.hpp"
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2009-04-21 23:21:04 -07:00
|
|
|
// Computes a CPC map (new_index -> original_index) for constant pool entries
|
2007-12-01 00:00:00 +00:00
|
|
|
// that are referred to by the interpreter at runtime via the constant pool cache.
|
2009-04-21 23:21:04 -07:00
|
|
|
// Also computes a CP map (original_index -> new_index).
|
|
|
|
// Marks entries in CP which require additional processing.
|
|
|
|
void Rewriter::compute_index_maps() {
|
|
|
|
const int length = _pool->length();
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
init_maps(length);
|
2012-07-24 10:51:00 -07:00
|
|
|
bool saw_mh_symbol = false;
|
2007-12-01 00:00:00 +00:00
|
|
|
for (int i = 0; i < length; i++) {
|
2009-04-21 23:21:04 -07:00
|
|
|
int tag = _pool->tag_at(i).value();
|
|
|
|
switch (tag) {
|
|
|
|
case JVM_CONSTANT_InterfaceMethodref:
|
2007-12-01 00:00:00 +00:00
|
|
|
case JVM_CONSTANT_Fieldref : // fall through
|
|
|
|
case JVM_CONSTANT_Methodref : // fall through
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
add_cp_cache_entry(i);
|
|
|
|
break;
|
|
|
|
case JVM_CONSTANT_String:
|
2010-06-09 18:50:45 -07:00
|
|
|
case JVM_CONSTANT_MethodHandle : // fall through
|
|
|
|
case JVM_CONSTANT_MethodType : // fall through
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
add_resolved_references_entry(i);
|
2009-04-21 23:21:04 -07:00
|
|
|
break;
|
2012-07-24 10:51:00 -07:00
|
|
|
case JVM_CONSTANT_Utf8:
|
2016-03-24 11:21:49 +01:00
|
|
|
if (_pool->symbol_at(i) == vmSymbols::java_lang_invoke_MethodHandle() ||
|
|
|
|
_pool->symbol_at(i) == vmSymbols::java_lang_invoke_VarHandle()) {
|
2012-07-24 10:51:00 -07:00
|
|
|
saw_mh_symbol = true;
|
2016-03-24 11:21:49 +01:00
|
|
|
}
|
2012-07-24 10:51:00 -07:00
|
|
|
break;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-21 23:21:04 -07:00
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// Record limits of resolved reference map for constant pool cache indices
|
|
|
|
record_map_limits();
|
|
|
|
|
2009-04-21 23:21:04 -07:00
|
|
|
guarantee((int)_cp_cache_map.length()-1 <= (int)((u2)-1),
|
|
|
|
"all cp cache indexes fit in a u2");
|
2010-07-15 18:40:45 -07:00
|
|
|
|
2012-07-24 10:51:00 -07:00
|
|
|
if (saw_mh_symbol)
|
|
|
|
_method_handle_invokers.initialize(length, (int)0);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2011-05-21 15:39:54 -07:00
|
|
|
// Unrewrite the bytecodes if an error occurs.
|
2013-11-15 17:20:22 -05:00
|
|
|
void Rewriter::restore_bytecodes() {
|
2011-05-21 15:39:54 -07:00
|
|
|
int len = _methods->length();
|
2013-11-15 17:20:22 -05:00
|
|
|
bool invokespecial_error = false;
|
2011-05-21 15:39:54 -07:00
|
|
|
|
|
|
|
for (int i = len-1; i >= 0; i--) {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Method* method = _methods->at(i);
|
2013-11-15 17:20:22 -05:00
|
|
|
scan_method(method, true, &invokespecial_error);
|
|
|
|
assert(!invokespecial_error, "reversing should not get an invokespecial error");
|
2011-05-21 15:39:54 -07:00
|
|
|
}
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2009-04-21 23:21:04 -07:00
|
|
|
// Creates a constant pool cache given a CPC map
|
|
|
|
void Rewriter::make_constant_pool_cache(TRAPS) {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
ClassLoaderData* loader_data = _pool->pool_holder()->class_loader_data();
|
|
|
|
ConstantPoolCache* cache =
|
2013-11-13 16:42:24 -05:00
|
|
|
ConstantPoolCache::allocate(loader_data, _cp_cache_map,
|
|
|
|
_invokedynamic_cp_cache_map,
|
2013-03-08 11:47:57 -05:00
|
|
|
_invokedynamic_references_map, CHECK);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
|
|
|
|
// initialize object cache in constant pool
|
|
|
|
_pool->initialize_resolved_references(loader_data, _resolved_references_map,
|
|
|
|
_resolved_reference_limit,
|
|
|
|
CHECK);
|
2009-04-21 23:21:04 -07:00
|
|
|
_pool->set_cache(cache);
|
|
|
|
cache->set_constant_pool(_pool());
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
Annotate possibly intrinsified methods with @HotSpotIntrinsicCandidate. Add checks omitted by intrinsics to the library code. Add CheckIntrinsics flags to check consistency of intrinsics.
Reviewed-by: jrose, kvn, thartmann, vlivanov, abuckley, darcy, ascarpino, briangoetz, alanb, aph, dnsimon
2015-07-03 07:25:03 +02:00
|
|
|
// available to pass to the registration function. For simplicity we
|
2007-12-01 00:00:00 +00:00
|
|
|
// require that local 0 is never overwritten so it's available as an
|
|
|
|
// argument for registration.
|
|
|
|
|
|
|
|
void Rewriter::rewrite_Object_init(methodHandle method, TRAPS) {
|
|
|
|
RawBytecodeStream bcs(method);
|
|
|
|
while (!bcs.is_last_bytecode()) {
|
|
|
|
Bytecodes::Code opcode = bcs.raw_next();
|
|
|
|
switch (opcode) {
|
|
|
|
case Bytecodes::_return: *bcs.bcp() = Bytecodes::_return_register_finalizer; break;
|
|
|
|
|
|
|
|
case Bytecodes::_istore:
|
|
|
|
case Bytecodes::_lstore:
|
|
|
|
case Bytecodes::_fstore:
|
|
|
|
case Bytecodes::_dstore:
|
|
|
|
case Bytecodes::_astore:
|
|
|
|
if (bcs.get_index() != 0) continue;
|
|
|
|
|
|
|
|
// fall through
|
|
|
|
case Bytecodes::_istore_0:
|
|
|
|
case Bytecodes::_lstore_0:
|
|
|
|
case Bytecodes::_fstore_0:
|
|
|
|
case Bytecodes::_dstore_0:
|
|
|
|
case Bytecodes::_astore_0:
|
|
|
|
THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
|
|
|
|
"can't overwrite local 0 in Object.<init>");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-21 23:21:04 -07:00
|
|
|
// Rewrite a classfile-order CP index into a native-order CPC index.
|
2011-05-21 15:39:54 -07:00
|
|
|
void Rewriter::rewrite_member_reference(address bcp, int offset, bool reverse) {
|
2009-04-21 23:21:04 -07:00
|
|
|
address p = bcp + offset;
|
2011-05-21 15:39:54 -07:00
|
|
|
if (!reverse) {
|
|
|
|
int cp_index = Bytes::get_Java_u2(p);
|
|
|
|
int cache_index = cp_entry_to_cp_cache(cp_index);
|
|
|
|
Bytes::put_native_u2(p, cache_index);
|
2012-07-24 10:51:00 -07:00
|
|
|
if (!_method_handle_invokers.is_empty())
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
maybe_rewrite_invokehandle(p - 1, cp_index, cache_index, reverse);
|
2011-05-21 15:39:54 -07:00
|
|
|
} else {
|
|
|
|
int cache_index = Bytes::get_native_u2(p);
|
|
|
|
int pool_index = cp_cache_entry_pool_index(cache_index);
|
|
|
|
Bytes::put_Java_u2(p, pool_index);
|
2012-07-24 10:51:00 -07:00
|
|
|
if (!_method_handle_invokers.is_empty())
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
maybe_rewrite_invokehandle(p - 1, pool_index, cache_index, reverse);
|
2012-07-24 10:51:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-13 16:42:24 -05:00
|
|
|
// If the constant pool entry for invokespecial is InterfaceMethodref,
|
|
|
|
// we need to add a separate cpCache entry for its resolution, because it is
|
|
|
|
// different than the resolution for invokeinterface with InterfaceMethodref.
|
|
|
|
// These cannot share cpCache entries. It's unclear if all invokespecial to
|
|
|
|
// InterfaceMethodrefs would resolve to the same thing so a new cpCache entry
|
|
|
|
// is created for each one. This was added with lambda.
|
2013-11-15 17:20:22 -05:00
|
|
|
void Rewriter::rewrite_invokespecial(address bcp, int offset, bool reverse, bool* invokespecial_error) {
|
2013-11-13 16:42:24 -05:00
|
|
|
address p = bcp + offset;
|
|
|
|
if (!reverse) {
|
|
|
|
int cp_index = Bytes::get_Java_u2(p);
|
2013-11-15 17:20:22 -05:00
|
|
|
if (_pool->tag_at(cp_index).is_interface_method()) {
|
2015-03-25 15:18:37 -07:00
|
|
|
int cache_index = add_invokespecial_cp_cache_entry(cp_index);
|
|
|
|
if (cache_index != (int)(jushort) cache_index) {
|
|
|
|
*invokespecial_error = true;
|
|
|
|
}
|
|
|
|
Bytes::put_native_u2(p, cache_index);
|
|
|
|
} else {
|
2013-11-15 17:20:22 -05:00
|
|
|
rewrite_member_reference(bcp, offset, reverse);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rewrite_member_reference(bcp, offset, reverse);
|
2013-11-13 16:42:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-24 10:51:00 -07:00
|
|
|
|
|
|
|
// Adjust the invocation bytecode for a signature-polymorphic method (MethodHandle.invoke, etc.)
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
void Rewriter::maybe_rewrite_invokehandle(address opc, int cp_index, int cache_index, bool reverse) {
|
2012-07-24 10:51:00 -07:00
|
|
|
if (!reverse) {
|
|
|
|
if ((*opc) == (u1)Bytecodes::_invokevirtual ||
|
|
|
|
// allow invokespecial as an alias, although it would be very odd:
|
|
|
|
(*opc) == (u1)Bytecodes::_invokespecial) {
|
|
|
|
assert(_pool->tag_at(cp_index).is_method(), "wrong index");
|
|
|
|
// Determine whether this is a signature-polymorphic method.
|
|
|
|
if (cp_index >= _method_handle_invokers.length()) return;
|
|
|
|
int status = _method_handle_invokers[cp_index];
|
|
|
|
assert(status >= -1 && status <= 1, "oob tri-state");
|
|
|
|
if (status == 0) {
|
|
|
|
if (_pool->klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_MethodHandle() &&
|
|
|
|
MethodHandles::is_signature_polymorphic_name(SystemDictionary::MethodHandle_klass(),
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
_pool->name_ref_at(cp_index))) {
|
|
|
|
// we may need a resolved_refs entry for the appendix
|
2012-10-01 14:50:10 -07:00
|
|
|
add_invokedynamic_resolved_references_entries(cp_index, cache_index);
|
2012-07-24 10:51:00 -07:00
|
|
|
status = +1;
|
2016-03-24 11:21:49 +01:00
|
|
|
} else if (_pool->klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_VarHandle() &&
|
|
|
|
MethodHandles::is_signature_polymorphic_name(SystemDictionary::VarHandle_klass(),
|
|
|
|
_pool->name_ref_at(cp_index))) {
|
|
|
|
// we may need a resolved_refs entry for the appendix
|
|
|
|
add_invokedynamic_resolved_references_entries(cp_index, cache_index);
|
|
|
|
status = +1;
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
} else {
|
2012-07-24 10:51:00 -07:00
|
|
|
status = -1;
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
}
|
2012-07-24 10:51:00 -07:00
|
|
|
_method_handle_invokers[cp_index] = status;
|
|
|
|
}
|
|
|
|
// We use a special internal bytecode for such methods (if non-static).
|
|
|
|
// The basic reason for this is that such methods need an extra "appendix" argument
|
|
|
|
// to transmit the call site's intended call type.
|
|
|
|
if (status > 0) {
|
|
|
|
(*opc) = (u1)Bytecodes::_invokehandle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Do not need to look at cp_index.
|
|
|
|
if ((*opc) == (u1)Bytecodes::_invokehandle) {
|
|
|
|
(*opc) = (u1)Bytecodes::_invokevirtual;
|
|
|
|
// Ignore corner case of original _invokespecial instruction.
|
|
|
|
// This is safe because (a) the signature polymorphic method was final, and
|
|
|
|
// (b) the implementation of MethodHandle will not call invokespecial on it.
|
|
|
|
}
|
2011-05-21 15:39:54 -07:00
|
|
|
}
|
2009-04-21 23:21:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-21 15:39:54 -07:00
|
|
|
void Rewriter::rewrite_invokedynamic(address bcp, int offset, bool reverse) {
|
2009-04-21 23:21:04 -07:00
|
|
|
address p = bcp + offset;
|
2011-05-21 15:39:54 -07:00
|
|
|
assert(p[-1] == Bytecodes::_invokedynamic, "not invokedynamic bytecode");
|
|
|
|
if (!reverse) {
|
|
|
|
int cp_index = Bytes::get_Java_u2(p);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
int cache_index = add_invokedynamic_cp_cache_entry(cp_index);
|
2013-11-13 16:42:24 -05:00
|
|
|
int resolved_index = add_invokedynamic_resolved_references_entries(cp_index, cache_index);
|
2011-05-21 15:39:54 -07:00
|
|
|
// Replace the trailing four bytes with a CPC index for the dynamic
|
|
|
|
// call site. Unlike other CPC entries, there is one per bytecode,
|
|
|
|
// not just one per distinct CP entry. In other words, the
|
|
|
|
// CPC-to-CP relation is many-to-one for invokedynamic entries.
|
|
|
|
// This means we must use a larger index size than u2 to address
|
|
|
|
// all these entries. That is the main reason invokedynamic
|
|
|
|
// must have a five-byte instruction format. (Of course, other JVM
|
|
|
|
// implementations can use the bytes for other purposes.)
|
|
|
|
// Note: We use native_u4 format exclusively for 4-byte indexes.
|
2013-11-13 16:42:24 -05:00
|
|
|
Bytes::put_native_u4(p, ConstantPool::encode_invokedynamic_index(cache_index));
|
|
|
|
// add the bcp in case we need to patch this bytecode if we also find a
|
|
|
|
// invokespecial/InterfaceMethodref in the bytecode stream
|
|
|
|
_patch_invokedynamic_bcps->push(p);
|
|
|
|
_patch_invokedynamic_refs->push(resolved_index);
|
2011-05-21 15:39:54 -07:00
|
|
|
} else {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
int cache_index = ConstantPool::decode_invokedynamic_index(
|
2011-05-21 15:39:54 -07:00
|
|
|
Bytes::get_native_u4(p));
|
2013-11-13 16:42:24 -05:00
|
|
|
// We will reverse the bytecode rewriting _after_ adjusting them.
|
|
|
|
// Adjust the cache index by offset to the invokedynamic entries in the
|
|
|
|
// cpCache plus the delta if the invokedynamic bytecodes were adjusted.
|
2014-02-07 18:30:27 -05:00
|
|
|
int adjustment = cp_cache_delta() + _first_iteration_cp_cache_limit;
|
|
|
|
int cp_index = invokedynamic_cp_cache_entry_pool_index(cache_index - adjustment);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
assert(_pool->tag_at(cp_index).is_invoke_dynamic(), "wrong index");
|
2011-05-21 15:39:54 -07:00
|
|
|
// zero out 4 bytes
|
|
|
|
Bytes::put_Java_u4(p, 0);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Bytes::put_Java_u2(p, cp_index);
|
2011-05-21 15:39:54 -07:00
|
|
|
}
|
2009-04-21 23:21:04 -07:00
|
|
|
}
|
|
|
|
|
2013-11-13 16:42:24 -05:00
|
|
|
void Rewriter::patch_invokedynamic_bytecodes() {
|
|
|
|
// If the end of the cp_cache is the same as after initializing with the
|
|
|
|
// cpool, nothing needs to be done. Invokedynamic bytecodes are at the
|
|
|
|
// correct offsets. ie. no invokespecials added
|
|
|
|
int delta = cp_cache_delta();
|
|
|
|
if (delta > 0) {
|
|
|
|
int length = _patch_invokedynamic_bcps->length();
|
|
|
|
assert(length == _patch_invokedynamic_refs->length(),
|
|
|
|
"lengths should match");
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
address p = _patch_invokedynamic_bcps->at(i);
|
|
|
|
int cache_index = ConstantPool::decode_invokedynamic_index(
|
|
|
|
Bytes::get_native_u4(p));
|
|
|
|
Bytes::put_native_u4(p, ConstantPool::encode_invokedynamic_index(cache_index + delta));
|
|
|
|
|
|
|
|
// invokedynamic resolved references map also points to cp cache and must
|
|
|
|
// add delta to each.
|
|
|
|
int resolved_index = _patch_invokedynamic_refs->at(i);
|
|
|
|
for (int entry = 0; entry < ConstantPoolCacheEntry::_indy_resolved_references_entries; entry++) {
|
|
|
|
assert(_invokedynamic_references_map[resolved_index+entry] == cache_index,
|
|
|
|
"should be the same index");
|
|
|
|
_invokedynamic_references_map.at_put(resolved_index+entry,
|
|
|
|
cache_index + delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-21 23:21:04 -07:00
|
|
|
|
2010-06-09 18:50:45 -07:00
|
|
|
// Rewrite some ldc bytecodes to _fast_aldc
|
2011-05-21 15:39:54 -07:00
|
|
|
void Rewriter::maybe_rewrite_ldc(address bcp, int offset, bool is_wide,
|
|
|
|
bool reverse) {
|
|
|
|
if (!reverse) {
|
|
|
|
assert((*bcp) == (is_wide ? Bytecodes::_ldc_w : Bytecodes::_ldc), "not ldc bytecode");
|
|
|
|
address p = bcp + offset;
|
|
|
|
int cp_index = is_wide ? Bytes::get_Java_u2(p) : (u1)(*p);
|
|
|
|
constantTag tag = _pool->tag_at(cp_index).value();
|
2013-02-22 08:36:42 -05:00
|
|
|
if (tag.is_method_handle() || tag.is_method_type() || tag.is_string()) {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
int ref_index = cp_entry_to_resolved_references(cp_index);
|
2011-05-21 15:39:54 -07:00
|
|
|
if (is_wide) {
|
|
|
|
(*bcp) = Bytecodes::_fast_aldc_w;
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
assert(ref_index == (u2)ref_index, "index overflow");
|
|
|
|
Bytes::put_native_u2(p, ref_index);
|
2011-05-21 15:39:54 -07:00
|
|
|
} else {
|
|
|
|
(*bcp) = Bytecodes::_fast_aldc;
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
assert(ref_index == (u1)ref_index, "index overflow");
|
|
|
|
(*p) = (u1)ref_index;
|
2011-05-21 15:39:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Bytecodes::Code rewritten_bc =
|
|
|
|
(is_wide ? Bytecodes::_fast_aldc_w : Bytecodes::_fast_aldc);
|
|
|
|
if ((*bcp) == rewritten_bc) {
|
|
|
|
address p = bcp + offset;
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
int ref_index = is_wide ? Bytes::get_native_u2(p) : (u1)(*p);
|
|
|
|
int pool_index = resolved_references_entry_to_pool_index(ref_index);
|
2011-05-21 15:39:54 -07:00
|
|
|
if (is_wide) {
|
|
|
|
(*bcp) = Bytecodes::_ldc_w;
|
|
|
|
assert(pool_index == (u2)pool_index, "index overflow");
|
|
|
|
Bytes::put_Java_u2(p, pool_index);
|
|
|
|
} else {
|
|
|
|
(*bcp) = Bytecodes::_ldc;
|
|
|
|
assert(pool_index == (u1)pool_index, "index overflow");
|
|
|
|
(*p) = (u1)pool_index;
|
|
|
|
}
|
2010-06-09 18:50:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Rewrites a method given the index_map information
|
2013-11-15 17:20:22 -05:00
|
|
|
void Rewriter::scan_method(Method* method, bool reverse, bool* invokespecial_error) {
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
int nof_jsrs = 0;
|
|
|
|
bool has_monitor_bytecodes = false;
|
|
|
|
|
|
|
|
{
|
|
|
|
// We cannot tolerate a GC in this block, because we've
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// cached the bytecodes in 'code_base'. If the Method*
|
2007-12-01 00:00:00 +00:00
|
|
|
// moves, the bytecodes will also move.
|
2016-01-14 13:26:19 +01:00
|
|
|
NoSafepointVerifier nsv;
|
2007-12-01 00:00:00 +00:00
|
|
|
Bytecodes::Code c;
|
|
|
|
|
|
|
|
// Bytecodes and their length
|
|
|
|
const address code_base = method->code_base();
|
|
|
|
const int code_length = method->code_size();
|
|
|
|
|
|
|
|
int bc_length;
|
|
|
|
for (int bci = 0; bci < code_length; bci += bc_length) {
|
|
|
|
address bcp = code_base + bci;
|
2009-04-21 23:21:04 -07:00
|
|
|
int prefix_length = 0;
|
2007-12-01 00:00:00 +00:00
|
|
|
c = (Bytecodes::Code)(*bcp);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
bc_length = Bytecodes::length_for(c);
|
|
|
|
if (bc_length == 0) {
|
2011-01-13 22:15:41 -08:00
|
|
|
bc_length = Bytecodes::length_at(method, bcp);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// 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...
|
|
|
|
if (c == Bytecodes::_wide) {
|
2009-04-21 23:21:04 -07:00
|
|
|
prefix_length = 1;
|
2007-12-01 00:00:00 +00:00
|
|
|
c = (Bytecodes::Code)bcp[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(bc_length != 0, "impossible bytecode length");
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case Bytecodes::_lookupswitch : {
|
|
|
|
#ifndef CC_INTERP
|
2011-01-13 22:15:41 -08:00
|
|
|
Bytecode_lookupswitch bc(method, bcp);
|
2010-05-23 01:38:26 -07:00
|
|
|
(*bcp) = (
|
2011-01-13 22:15:41 -08:00
|
|
|
bc.number_of_pairs() < BinarySwitchThreshold
|
2007-12-01 00:00:00 +00:00
|
|
|
? Bytecodes::_fast_linearswitch
|
|
|
|
: Bytecodes::_fast_binaryswitch
|
|
|
|
);
|
2011-05-21 15:39:54 -07:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Bytecodes::_fast_linearswitch:
|
|
|
|
case Bytecodes::_fast_binaryswitch: {
|
|
|
|
#ifndef CC_INTERP
|
|
|
|
(*bcp) = Bytecodes::_lookupswitch;
|
2007-12-01 00:00:00 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
2013-11-13 16:42:24 -05:00
|
|
|
|
|
|
|
case Bytecodes::_invokespecial : {
|
2013-11-15 17:20:22 -05:00
|
|
|
rewrite_invokespecial(bcp, prefix_length+1, reverse, invokespecial_error);
|
2013-11-13 16:42:24 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
case Bytecodes::_getstatic : // fall through
|
|
|
|
case Bytecodes::_putstatic : // fall through
|
|
|
|
case Bytecodes::_getfield : // fall through
|
|
|
|
case Bytecodes::_putfield : // fall through
|
|
|
|
case Bytecodes::_invokevirtual : // fall through
|
2009-04-21 23:21:04 -07:00
|
|
|
case Bytecodes::_invokestatic :
|
|
|
|
case Bytecodes::_invokeinterface:
|
2012-07-24 10:51:00 -07:00
|
|
|
case Bytecodes::_invokehandle : // if reverse=true
|
2011-05-21 15:39:54 -07:00
|
|
|
rewrite_member_reference(bcp, prefix_length+1, reverse);
|
2009-04-21 23:21:04 -07:00
|
|
|
break;
|
|
|
|
case Bytecodes::_invokedynamic:
|
2011-05-21 15:39:54 -07:00
|
|
|
rewrite_invokedynamic(bcp, prefix_length+1, reverse);
|
2007-12-01 00:00:00 +00:00
|
|
|
break;
|
2010-06-09 18:50:45 -07:00
|
|
|
case Bytecodes::_ldc:
|
2012-07-24 10:51:00 -07:00
|
|
|
case Bytecodes::_fast_aldc: // if reverse=true
|
2011-05-21 15:39:54 -07:00
|
|
|
maybe_rewrite_ldc(bcp, prefix_length+1, false, reverse);
|
2010-06-09 18:50:45 -07:00
|
|
|
break;
|
|
|
|
case Bytecodes::_ldc_w:
|
2012-07-24 10:51:00 -07:00
|
|
|
case Bytecodes::_fast_aldc_w: // if reverse=true
|
2011-05-21 15:39:54 -07:00
|
|
|
maybe_rewrite_ldc(bcp, prefix_length+1, true, reverse);
|
2010-06-09 18:50:45 -07:00
|
|
|
break;
|
2007-12-01 00:00:00 +00:00
|
|
|
case Bytecodes::_jsr : // fall through
|
|
|
|
case Bytecodes::_jsr_w : nof_jsrs++; break;
|
|
|
|
case Bytecodes::_monitorenter : // fall through
|
|
|
|
case Bytecodes::_monitorexit : has_monitor_bytecodes = true; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update access flags
|
|
|
|
if (has_monitor_bytecodes) {
|
|
|
|
method->set_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();
|
2009-04-21 23:21:04 -07:00
|
|
|
// Second pass will revisit this method.
|
2011-05-21 15:39:54 -07:00
|
|
|
assert(method->has_jsrs(), "didn't we just set this?");
|
2009-04-21 23:21:04 -07:00
|
|
|
}
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2009-04-21 23:21:04 -07:00
|
|
|
// After constant pool is created, revisit methods containing jsrs.
|
|
|
|
methodHandle Rewriter::rewrite_jsrs(methodHandle method, TRAPS) {
|
2011-05-21 15:39:54 -07:00
|
|
|
ResourceMark rm(THREAD);
|
2009-04-21 23:21:04 -07:00
|
|
|
ResolveOopMapConflicts romc(method);
|
|
|
|
methodHandle original_method = method;
|
|
|
|
method = romc.do_potential_rewrite(CHECK_(methodHandle()));
|
|
|
|
// Update monitor matching info.
|
|
|
|
if (romc.monitor_safe()) {
|
|
|
|
method->set_guaranteed_monitor_matching();
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
return method;
|
|
|
|
}
|
|
|
|
|
2014-02-07 18:30:27 -05:00
|
|
|
void Rewriter::rewrite_bytecodes(TRAPS) {
|
2009-04-21 23:21:04 -07:00
|
|
|
assert(_pool->cache() == NULL, "constant pool cache must not be set yet");
|
2007-12-01 00:00:00 +00:00
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// determine index maps for Method* rewriting
|
2009-04-21 23:21:04 -07:00
|
|
|
compute_index_maps();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2009-04-21 23:21:04 -07:00
|
|
|
if (RegisterFinalizersAtInit && _klass->name() == vmSymbols::java_lang_Object()) {
|
2009-07-21 16:56:06 -07:00
|
|
|
bool did_rewrite = false;
|
2009-04-21 23:21:04 -07:00
|
|
|
int i = _methods->length();
|
2007-12-01 00:00:00 +00:00
|
|
|
while (i-- > 0) {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Method* method = _methods->at(i);
|
2007-12-01 00:00:00 +00:00
|
|
|
if (method->intrinsic_id() == vmIntrinsics::_Object_init) {
|
|
|
|
// rewrite the return bytecodes of Object.<init> to register the
|
|
|
|
// object for finalization if needed.
|
|
|
|
methodHandle m(THREAD, method);
|
|
|
|
rewrite_Object_init(m, CHECK);
|
2009-07-21 16:56:06 -07:00
|
|
|
did_rewrite = true;
|
2007-12-01 00:00:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-07-21 16:56:06 -07:00
|
|
|
assert(did_rewrite, "must find Object::<init> to rewrite it");
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2009-04-21 23:21:04 -07:00
|
|
|
// rewrite methods, in two passes
|
2011-05-21 15:39:54 -07:00
|
|
|
int len = _methods->length();
|
2013-11-15 17:20:22 -05:00
|
|
|
bool invokespecial_error = false;
|
2009-04-21 23:21:04 -07:00
|
|
|
|
2011-05-21 15:39:54 -07:00
|
|
|
for (int i = len-1; i >= 0; i--) {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Method* method = _methods->at(i);
|
2013-11-15 17:20:22 -05:00
|
|
|
scan_method(method, false, &invokespecial_error);
|
|
|
|
if (invokespecial_error) {
|
|
|
|
// If you get an error here, there is no reversing bytecodes
|
|
|
|
// This exception is stored for this class and no further attempt is
|
|
|
|
// made at verifying or rewriting.
|
|
|
|
THROW_MSG(vmSymbols::java_lang_InternalError(),
|
|
|
|
"This classfile overflows invokespecial for interfaces "
|
|
|
|
"and cannot be loaded");
|
|
|
|
return;
|
|
|
|
}
|
2009-04-21 23:21:04 -07:00
|
|
|
}
|
|
|
|
|
2013-11-13 16:42:24 -05:00
|
|
|
// May have to fix invokedynamic bytecodes if invokestatic/InterfaceMethodref
|
|
|
|
// entries had to be added.
|
|
|
|
patch_invokedynamic_bytecodes();
|
2014-02-07 18:30:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void Rewriter::rewrite(instanceKlassHandle klass, TRAPS) {
|
2015-03-25 15:18:37 -07:00
|
|
|
if (!DumpSharedSpaces) {
|
|
|
|
assert(!MetaspaceShared::is_in_shared_space(klass()), "archive methods must not be rewritten at run time");
|
|
|
|
}
|
2014-02-07 18:30:27 -05:00
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
Rewriter rw(klass, klass->constants(), klass->methods(), CHECK);
|
|
|
|
// (That's all, folks.)
|
|
|
|
}
|
|
|
|
|
2015-10-23 16:48:38 -04:00
|
|
|
Rewriter::Rewriter(instanceKlassHandle klass, const constantPoolHandle& cpool, Array<Method*>* methods, TRAPS)
|
2014-02-07 18:30:27 -05:00
|
|
|
: _klass(klass),
|
|
|
|
_pool(cpool),
|
|
|
|
_methods(methods)
|
|
|
|
{
|
|
|
|
|
|
|
|
// Rewrite bytecodes - exception here exits.
|
|
|
|
rewrite_bytecodes(CHECK);
|
|
|
|
|
|
|
|
// Stress restoring bytecodes
|
|
|
|
if (StressRewriter) {
|
|
|
|
restore_bytecodes();
|
|
|
|
rewrite_bytecodes(CHECK);
|
|
|
|
}
|
2013-11-13 16:42:24 -05:00
|
|
|
|
2009-04-21 23:21:04 -07:00
|
|
|
// allocate constant pool cache, now that we've seen all the bytecodes
|
2011-05-21 15:39:54 -07:00
|
|
|
make_constant_pool_cache(THREAD);
|
|
|
|
|
|
|
|
// Restore bytecodes to their unrewritten state if there are exceptions
|
|
|
|
// rewriting bytecodes or allocating the cpCache
|
|
|
|
if (HAS_PENDING_EXCEPTION) {
|
2013-11-15 17:20:22 -05:00
|
|
|
restore_bytecodes();
|
2011-05-21 15:39:54 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-02 20:28:09 -05:00
|
|
|
// Relocate after everything, but still do this under the is_rewritten flag,
|
|
|
|
// so methods with jsrs in custom class lists in aren't attempted to be
|
|
|
|
// rewritten in the RO section of the shared archive.
|
|
|
|
// Relocated bytecodes don't have to be restored, only the cp cache entries
|
2014-02-07 18:30:27 -05:00
|
|
|
int len = _methods->length();
|
2011-05-21 15:39:54 -07:00
|
|
|
for (int i = len-1; i >= 0; i--) {
|
2013-01-02 20:28:09 -05:00
|
|
|
methodHandle m(THREAD, _methods->at(i));
|
2009-04-21 23:21:04 -07:00
|
|
|
|
|
|
|
if (m->has_jsrs()) {
|
2013-01-02 20:28:09 -05:00
|
|
|
m = rewrite_jsrs(m, THREAD);
|
|
|
|
// Restore bytecodes to their unrewritten state if there are exceptions
|
|
|
|
// relocating bytecodes. If some are relocated, that is ok because that
|
|
|
|
// doesn't affect constant pool to cpCache rewriting.
|
|
|
|
if (HAS_PENDING_EXCEPTION) {
|
2013-11-15 17:20:22 -05:00
|
|
|
restore_bytecodes();
|
2013-01-02 20:28:09 -05:00
|
|
|
return;
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
// Method might have gotten rewritten.
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
methods->at_put(i, m());
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|