rewriter.hpp revision 726
0N/A/*
844N/A * Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
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 *
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 *
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 *
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 *
0N/A */
0N/A
0N/A// The Rewriter adds caches to the constant pool and rewrites bytecode indices
0N/A// pointing into the constant pool for better interpreter performance.
0N/A
726N/Aclass Rewriter: public StackObj {
0N/A private:
726N/A instanceKlassHandle _klass;
726N/A constantPoolHandle _pool;
726N/A objArrayHandle _methods;
726N/A intArray _cp_map;
726N/A intStack _cp_cache_map;
726N/A
726N/A void init_cp_map(int length) {
726N/A _cp_map.initialize(length, -1);
726N/A // Choose an initial value large enough that we don't get frequent
726N/A // calls to grow().
726N/A _cp_cache_map.initialize(length / 2);
726N/A }
726N/A int cp_entry_to_cp_cache(int i) { assert(has_cp_cache(i), "oob"); return _cp_map[i]; }
726N/A bool has_cp_cache(int i) { return (uint)i < (uint)_cp_map.length() && _cp_map[i] >= 0; }
726N/A int maybe_add_cp_cache_entry(int i) { return has_cp_cache(i) ? _cp_map[i] : add_cp_cache_entry(i); }
726N/A int add_cp_cache_entry(int cp_index) {
1059N/A assert(_cp_map[cp_index] == -1, "not twice on same cp_index");
726N/A int cache_index = _cp_cache_map.append(cp_index);
726N/A _cp_map.at_put(cp_index, cache_index);
726N/A assert(cp_entry_to_cp_cache(cp_index) == cache_index, "");
726N/A return cache_index;
726N/A }
726N/A int add_extra_cp_cache_entry(int main_entry);
1059N/A
1059N/A // All the work goes in here:
1059N/A Rewriter(instanceKlassHandle klass, TRAPS);
1059N/A
1059N/A void compute_index_maps();
726N/A void make_constant_pool_cache(TRAPS);
726N/A void scan_method(methodOop m);
726N/A methodHandle rewrite_jsrs(methodHandle m, TRAPS);
726N/A void rewrite_Object_init(methodHandle m, TRAPS);
726N/A int rewrite_member_reference(address bcp, int offset);
726N/A void rewrite_invokedynamic(address bcp, int offset, int cp_index);
726N/A
726N/A public:
726N/A // Driver routine:
726N/A static void rewrite(instanceKlassHandle klass, TRAPS);
726N/A};
0N/A