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
|
|
|
* Copyright (c) 1998, 2012, 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
|
|
|
#ifndef SHARE_VM_INTERPRETER_REWRITER_HPP
|
|
|
|
#define SHARE_VM_INTERPRETER_REWRITER_HPP
|
|
|
|
|
|
|
|
#include "memory/allocation.hpp"
|
|
|
|
#include "runtime/handles.inline.hpp"
|
|
|
|
#include "utilities/growableArray.hpp"
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// The Rewriter adds caches to the constant pool and rewrites bytecode indices
|
|
|
|
// pointing into the constant pool for better interpreter performance.
|
|
|
|
|
2009-04-21 23:21:04 -07:00
|
|
|
class Rewriter: public StackObj {
|
2007-12-01 00:00:00 +00:00
|
|
|
private:
|
2009-04-21 23:21:04 -07:00
|
|
|
instanceKlassHandle _klass;
|
|
|
|
constantPoolHandle _pool;
|
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
|
|
|
Array<Method*>* _methods;
|
2009-04-21 23:21:04 -07:00
|
|
|
intArray _cp_map;
|
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
|
|
|
intStack _cp_cache_map; // for Methodref, Fieldref,
|
|
|
|
// InterfaceMethodref and InvokeDynamic
|
|
|
|
intArray _reference_map; // maps from cp index to resolved_refs index (or -1)
|
|
|
|
intStack _resolved_references_map; // for strings, methodHandle, methodType
|
|
|
|
intStack _invokedynamic_references_map; // for invokedynamic resolved refs
|
2012-07-24 10:51:00 -07:00
|
|
|
intArray _method_handle_invokers;
|
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 _resolved_reference_limit;
|
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
|
|
|
void init_maps(int length) {
|
2009-04-21 23:21:04 -07:00
|
|
|
_cp_map.initialize(length, -1);
|
|
|
|
// Choose an initial value large enough that we don't get frequent
|
|
|
|
// calls to grow().
|
|
|
|
_cp_cache_map.initialize(length / 2);
|
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
|
|
|
// Also cache resolved objects, in another different cache.
|
|
|
|
_reference_map.initialize(length, -1);
|
|
|
|
_resolved_references_map.initialize(length / 2);
|
|
|
|
_invokedynamic_references_map.initialize(length / 2);
|
|
|
|
_resolved_reference_limit = -1;
|
|
|
|
DEBUG_ONLY(_cp_cache_index_limit = -1);
|
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
|
|
|
|
|
|
|
int _cp_cache_index_limit;
|
|
|
|
void record_map_limits() {
|
|
|
|
#ifdef ASSERT
|
|
|
|
// Record initial size of the two arrays generated for the CP cache:
|
|
|
|
_cp_cache_index_limit = _cp_cache_map.length();
|
|
|
|
#endif //ASSERT
|
|
|
|
_resolved_reference_limit = _resolved_references_map.length();
|
|
|
|
}
|
|
|
|
|
2009-04-21 23:21:04 -07:00
|
|
|
int cp_entry_to_cp_cache(int i) { assert(has_cp_cache(i), "oob"); return _cp_map[i]; }
|
|
|
|
bool has_cp_cache(int i) { return (uint)i < (uint)_cp_map.length() && _cp_map[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
|
|
|
|
2009-04-21 23:21:04 -07:00
|
|
|
int add_cp_cache_entry(int cp_index) {
|
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).value() != JVM_CONSTANT_InvokeDynamic, "use indy version");
|
2009-04-21 23:21:04 -07:00
|
|
|
assert(_cp_map[cp_index] == -1, "not twice on same cp_index");
|
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(_cp_cache_index_limit == -1, "do not add cache entries after first iteration");
|
2009-04-21 23:21:04 -07:00
|
|
|
int cache_index = _cp_cache_map.append(cp_index);
|
|
|
|
_cp_map.at_put(cp_index, cache_index);
|
|
|
|
assert(cp_entry_to_cp_cache(cp_index) == cache_index, "");
|
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(cp_cache_entry_pool_index(cache_index) == cp_index, "");
|
2009-04-21 23:21:04 -07:00
|
|
|
return cache_index;
|
|
|
|
}
|
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 a new CP cache entry beyond the normal cache (for invokedynamic only)
|
|
|
|
int add_invokedynamic_cp_cache_entry(int cp_index) {
|
|
|
|
assert(_pool->tag_at(cp_index).value() == JVM_CONSTANT_InvokeDynamic, "use non-indy version");
|
|
|
|
assert(_cp_map[cp_index] == -1, "do not map from cp_index");
|
|
|
|
assert(_cp_cache_index_limit >= 0, "add indy cache entries after first iteration");
|
|
|
|
int cache_index = _cp_cache_map.append(cp_index);
|
|
|
|
assert(cache_index >= _cp_cache_index_limit, "");
|
|
|
|
// do not update _cp_map, since the mapping is one-to-many
|
|
|
|
assert(cp_cache_entry_pool_index(cache_index) == cp_index, "");
|
2009-10-30 16:22:59 -07:00
|
|
|
return cache_index;
|
|
|
|
}
|
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
|
|
|
// fix duplicated code later
|
|
|
|
int cp_entry_to_resolved_references(int cp_index) const {
|
|
|
|
assert(has_entry_in_resolved_references(cp_index), "oob");
|
|
|
|
return _reference_map[cp_index];
|
|
|
|
}
|
|
|
|
bool has_entry_in_resolved_references(int cp_index) const {
|
|
|
|
return (uint)cp_index < (uint)_reference_map.length() && _reference_map[cp_index] >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add a new entry to the resolved_references map
|
|
|
|
int add_resolved_references_entry(int cp_index) {
|
|
|
|
assert(_reference_map[cp_index] == -1, "not twice on same cp_index");
|
|
|
|
assert(_resolved_reference_limit == -1, "do not add CP refs after first iteration");
|
|
|
|
int ref_index = _resolved_references_map.append(cp_index);
|
|
|
|
_reference_map.at_put(cp_index, ref_index);
|
|
|
|
assert(cp_entry_to_resolved_references(cp_index) == ref_index, "");
|
|
|
|
return ref_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add a new entry to the resolved_references map (for invokedynamic only)
|
|
|
|
int add_invokedynamic_resolved_references_entry(int cp_index, int cache_index) {
|
|
|
|
assert(_resolved_reference_limit >= 0, "must add indy refs after first iteration");
|
|
|
|
int ref_index = _resolved_references_map.append(cp_index); // many-to-one
|
|
|
|
assert(ref_index >= _resolved_reference_limit, "");
|
|
|
|
_invokedynamic_references_map.at_put_grow(ref_index, cache_index, -1);
|
|
|
|
return ref_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
int resolved_references_entry_to_pool_index(int ref_index) {
|
|
|
|
int cp_index = _resolved_references_map[ref_index];
|
|
|
|
return cp_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
// invokedynamic support - append the cpCache entry (encoded) in object map.
|
|
|
|
// The resolved_references_map should still be in ascending order
|
|
|
|
// The resolved_references has the invokedynamic call site objects appended after
|
|
|
|
// the objects that are resolved in the constant pool.
|
|
|
|
int add_callsite_entry(int main_cpc_entry) {
|
|
|
|
int ref_index = _resolved_references_map.append(main_cpc_entry);
|
|
|
|
return ref_index;
|
|
|
|
}
|
|
|
|
|
2010-07-15 18:40:45 -07:00
|
|
|
// Access the contents of _cp_cache_map to determine CP cache layout.
|
|
|
|
int cp_cache_entry_pool_index(int cache_index) {
|
|
|
|
int cp_index = _cp_cache_map[cache_index];
|
|
|
|
return cp_index;
|
|
|
|
}
|
|
|
|
|
2009-04-21 23:21:04 -07:00
|
|
|
// All the work goes in here:
|
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
|
|
|
Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, Array<Method*>* methods, TRAPS);
|
2009-04-21 23:21:04 -07:00
|
|
|
|
|
|
|
void compute_index_maps();
|
|
|
|
void 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
|
|
|
void scan_method(Method* m, bool reverse = false);
|
2009-04-21 23:21:04 -07:00
|
|
|
void rewrite_Object_init(methodHandle m, TRAPS);
|
2011-05-21 15:39:54 -07:00
|
|
|
void rewrite_member_reference(address bcp, int offset, bool reverse = false);
|
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 maybe_rewrite_invokehandle(address opc, int cp_index, int cache_index, bool reverse = false);
|
2011-05-21 15:39:54 -07:00
|
|
|
void rewrite_invokedynamic(address bcp, int offset, bool reverse = false);
|
|
|
|
void maybe_rewrite_ldc(address bcp, int offset, bool is_wide, bool reverse = false);
|
|
|
|
// Revert bytecodes in case of an exception.
|
|
|
|
void restore_bytecodes();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2011-05-21 15:39:54 -07:00
|
|
|
static methodHandle rewrite_jsrs(methodHandle m, TRAPS);
|
2007-12-01 00:00:00 +00:00
|
|
|
public:
|
2009-04-21 23:21:04 -07:00
|
|
|
// Driver routine:
|
2007-12-01 00:00:00 +00:00
|
|
|
static void rewrite(instanceKlassHandle klass, 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
|
|
|
static void rewrite(instanceKlassHandle klass, constantPoolHandle cpool, Array<Method*>* methods, TRAPS);
|
2011-05-21 15:39:54 -07:00
|
|
|
|
|
|
|
// Second pass, not gated by is_rewritten flag
|
|
|
|
static void relocate_and_link(instanceKlassHandle klass, TRAPS);
|
|
|
|
// JSR292 version to call with it's own methods.
|
|
|
|
static void relocate_and_link(instanceKlassHandle 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
|
|
|
Array<Method*>* methods, TRAPS);
|
2011-05-21 15:39:54 -07:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
2010-11-23 13:22:55 -08:00
|
|
|
|
|
|
|
#endif // SHARE_VM_INTERPRETER_REWRITER_HPP
|