author | twisti |
Tue, 05 Jan 2010 15:21:25 +0100 | |
changeset 4567 | 7fc02fbe5c7a |
parent 4429 | d7eb4e2099aa |
child 5688 | 9052dc91ea67 |
child 5547 | f4b087cbb361 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
3261 | 2 |
* Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 |
* have any questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
// The Rewriter adds caches to the constant pool and rewrites bytecode indices |
|
26 |
// pointing into the constant pool for better interpreter performance. |
|
27 |
||
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
28 |
class Rewriter: public StackObj { |
1 | 29 |
private: |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
30 |
instanceKlassHandle _klass; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
31 |
constantPoolHandle _pool; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
32 |
objArrayHandle _methods; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
33 |
intArray _cp_map; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
34 |
intStack _cp_cache_map; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
35 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
36 |
void init_cp_map(int length) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
37 |
_cp_map.initialize(length, -1); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
38 |
// Choose an initial value large enough that we don't get frequent |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
39 |
// calls to grow(). |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
40 |
_cp_cache_map.initialize(length / 2); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
41 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
42 |
int cp_entry_to_cp_cache(int i) { assert(has_cp_cache(i), "oob"); return _cp_map[i]; } |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
43 |
bool has_cp_cache(int i) { return (uint)i < (uint)_cp_map.length() && _cp_map[i] >= 0; } |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
44 |
int maybe_add_cp_cache_entry(int i) { return has_cp_cache(i) ? _cp_map[i] : add_cp_cache_entry(i); } |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
45 |
int add_cp_cache_entry(int cp_index) { |
4429
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3261
diff
changeset
|
46 |
assert((cp_index & _secondary_entry_tag) == 0, "bad tag"); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
47 |
assert(_cp_map[cp_index] == -1, "not twice on same cp_index"); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
48 |
int cache_index = _cp_cache_map.append(cp_index); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
49 |
_cp_map.at_put(cp_index, cache_index); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
50 |
assert(cp_entry_to_cp_cache(cp_index) == cache_index, ""); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
51 |
return cache_index; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
52 |
} |
4429
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3261
diff
changeset
|
53 |
int add_secondary_cp_cache_entry(int main_cpc_entry) { |
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3261
diff
changeset
|
54 |
assert(main_cpc_entry < _cp_cache_map.length(), "must be earlier CP cache entry"); |
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3261
diff
changeset
|
55 |
int cache_index = _cp_cache_map.append(main_cpc_entry | _secondary_entry_tag); |
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3261
diff
changeset
|
56 |
return cache_index; |
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3261
diff
changeset
|
57 |
} |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
58 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
59 |
// All the work goes in here: |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4429
diff
changeset
|
60 |
Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, objArrayHandle methods, TRAPS); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
61 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
62 |
void compute_index_maps(); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
63 |
void make_constant_pool_cache(TRAPS); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
64 |
void scan_method(methodOop m); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
65 |
methodHandle rewrite_jsrs(methodHandle m, TRAPS); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
66 |
void rewrite_Object_init(methodHandle m, TRAPS); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
67 |
int rewrite_member_reference(address bcp, int offset); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
68 |
void rewrite_invokedynamic(address bcp, int offset, int cp_index); |
1 | 69 |
|
70 |
public: |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
71 |
// Driver routine: |
1 | 72 |
static void rewrite(instanceKlassHandle klass, TRAPS); |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4429
diff
changeset
|
73 |
static void rewrite(instanceKlassHandle klass, constantPoolHandle cpool, objArrayHandle methods, TRAPS); |
4429
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3261
diff
changeset
|
74 |
|
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3261
diff
changeset
|
75 |
enum { |
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3261
diff
changeset
|
76 |
_secondary_entry_tag = nth_bit(30) |
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3261
diff
changeset
|
77 |
}; |
1 | 78 |
}; |