Mercurial > hg > graal-jvmci-8
annotate src/share/vm/prims/methodHandleWalk.hpp @ 1133:aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
Summary: We need a way to walk chained method handles in the JVM to call the right methods and to generate required bytecode adapters for the compilers.
Reviewed-by: kvn
author | twisti |
---|---|
date | Mon, 04 Jan 2010 15:52:40 +0100 |
parents | |
children | dd57230ba8fe |
rev | line source |
---|---|
1133
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
1 /* |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
2 * Copyright 2008-2010 Sun Microsystems, Inc. All Rights Reserved. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
4 * |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
8 * |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
13 * accompanied this code). |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
14 * |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
18 * |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
21 * have any questions. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
22 * |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
23 */ |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
24 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
25 // Low-level parser for method handle chains. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
26 class MethodHandleChain : StackObj { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
27 public: |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
28 typedef MethodHandles::EntryKind EntryKind; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
29 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
30 private: |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
31 Handle _root; // original target |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
32 Handle _method_handle; // current target |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
33 bool _is_last; // final guy in chain |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
34 bool _is_bound; // has a bound argument |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
35 BasicType _arg_type; // if is_bound, the bound argument type |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
36 int _arg_slot; // if is_bound or is_adapter, affected argument slot |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
37 jint _conversion; // conversion field of AMH or -1 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
38 methodHandle _last_method; // if is_last, which method we target |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
39 Bytecodes::Code _last_invoke; // if is_last, type of invoke |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
40 const char* _lose_message; // saved argument to lose() |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
41 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
42 void set_method_handle(Handle target, TRAPS); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
43 void set_last_method(oop target, TRAPS); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
44 static BasicType compute_bound_arg_type(oop target, methodOop m, int arg_slot, TRAPS); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
45 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
46 oop MethodHandle_type_oop() { return java_dyn_MethodHandle::type(method_handle_oop()); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
47 oop MethodHandle_vmtarget_oop() { return java_dyn_MethodHandle::vmtarget(method_handle_oop()); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
48 int MethodHandle_vmslots() { return java_dyn_MethodHandle::vmslots(method_handle_oop()); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
49 int DirectMethodHandle_vmindex() { return sun_dyn_DirectMethodHandle::vmindex(method_handle_oop()); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
50 oop BoundMethodHandle_argument_oop() { return sun_dyn_BoundMethodHandle::argument(method_handle_oop()); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
51 int BoundMethodHandle_vmargslot() { return sun_dyn_BoundMethodHandle::vmargslot(method_handle_oop()); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
52 int AdapterMethodHandle_conversion() { return sun_dyn_AdapterMethodHandle::conversion(method_handle_oop()); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
53 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
54 public: |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
55 MethodHandleChain(Handle root, TRAPS) |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
56 : _root(root) |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
57 { set_method_handle(root, THREAD); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
58 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
59 bool is_adapter() { return _conversion != -1; } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
60 bool is_bound() { return _is_bound; } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
61 bool is_last() { return _is_last; } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
62 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
63 void next(TRAPS) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
64 assert(!is_last(), ""); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
65 set_method_handle(MethodHandle_vmtarget_oop(), THREAD); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
66 } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
67 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
68 Handle method_handle() { return _method_handle; } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
69 oop method_handle_oop() { return _method_handle(); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
70 oop method_type_oop() { return MethodHandle_type_oop(); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
71 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
72 jint adapter_conversion() { assert(is_adapter(), ""); return _conversion; } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
73 int adapter_conversion_op() { return MethodHandles::adapter_conversion_op(adapter_conversion()); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
74 BasicType adapter_conversion_src_type() |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
75 { return MethodHandles::adapter_conversion_src_type(adapter_conversion()); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
76 BasicType adapter_conversion_dest_type() |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
77 { return MethodHandles::adapter_conversion_dest_type(adapter_conversion()); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
78 int adapter_conversion_stack_move() |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
79 { return MethodHandles::adapter_conversion_stack_move(adapter_conversion()); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
80 int adapter_conversion_stack_pushes() |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
81 { return adapter_conversion_stack_move() / MethodHandles::stack_move_unit(); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
82 int adapter_conversion_vminfo() |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
83 { return MethodHandles::adapter_conversion_vminfo(adapter_conversion()); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
84 int adapter_arg_slot() { assert(is_adapter(), ""); return _arg_slot; } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
85 oop adapter_arg_oop() { assert(is_adapter(), ""); return BoundMethodHandle_argument_oop(); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
86 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
87 BasicType bound_arg_type() { assert(is_bound(), ""); return _arg_type; } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
88 int bound_arg_slot() { assert(is_bound(), ""); return _arg_slot; } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
89 oop bound_arg_oop() { assert(is_bound(), ""); return BoundMethodHandle_argument_oop(); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
90 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
91 methodOop last_method_oop() { assert(is_last(), ""); return _last_method(); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
92 Bytecodes::Code last_invoke_code() { assert(is_last(), ""); return _last_invoke; } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
93 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
94 void lose(const char* msg, TRAPS); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
95 const char* lose_message() { return _lose_message; } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
96 }; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
97 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
98 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
99 // Structure walker for method handles. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
100 // Does abstract interpretation on top of low-level parsing. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
101 // You supply the tokens shuffled by the abstract interpretation. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
102 class MethodHandleWalker : StackObj { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
103 public: |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
104 struct _ArgToken { }; // dummy struct |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
105 typedef _ArgToken* ArgToken; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
106 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
107 // Abstract interpretation state: |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
108 struct SlotState { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
109 BasicType _type; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
110 ArgToken _arg; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
111 SlotState() : _type(), _arg() {} |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
112 }; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
113 static SlotState make_state(BasicType type, ArgToken arg) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
114 SlotState ss; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
115 ss._type = type; ss._arg = arg; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
116 return ss; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
117 } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
118 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
119 private: |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
120 MethodHandleChain _chain; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
121 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
122 GrowableArray<SlotState> _outgoing; // current outgoing parameter slots |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
123 int _outgoing_argc; // # non-empty outgoing slots |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
124 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
125 // Replace a value of type old_type at slot (and maybe slot+1) with the new value. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
126 // If old_type != T_VOID, remove the old argument at that point. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
127 // If new_type != T_VOID, insert the new argument at that point. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
128 // Insert or delete a second empty slot as needed. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
129 void change_argument(BasicType old_type, int slot, BasicType new_type, ArgToken new_arg); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
130 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
131 SlotState* slot_state(int slot) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
132 if (slot < 0 || slot >= _outgoing.length()) |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
133 return NULL; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
134 return _outgoing.adr_at(slot); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
135 } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
136 BasicType slot_type(int slot) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
137 SlotState* ss = slot_state(slot); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
138 if (ss == NULL) |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
139 return T_ILLEGAL; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
140 return ss->_type; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
141 } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
142 bool slot_has_argument(int slot) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
143 return slot_type(slot) < T_VOID; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
144 } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
145 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
146 #ifdef ASSERT |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
147 int argument_count_slow(); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
148 #endif |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
149 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
150 // Return a bytecode for converting src to dest, if one exists. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
151 Bytecodes::Code conversion_code(BasicType src, BasicType dest); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
152 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
153 void walk_incoming_state(TRAPS); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
154 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
155 public: |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
156 MethodHandleWalker(Handle root, TRAPS) |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
157 : _chain(root, THREAD), |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
158 _outgoing(THREAD, 10), |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
159 _outgoing_argc(0) |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
160 { } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
161 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
162 MethodHandleChain& chain() { return _chain; } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
163 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
164 // plug-in abstract interpretation steps: |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
165 virtual ArgToken make_parameter( BasicType type, klassOop tk, int argnum, TRAPS ) = 0; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
166 virtual ArgToken make_prim_constant( BasicType type, jvalue* con, TRAPS ) = 0; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
167 virtual ArgToken make_oop_constant( oop con, TRAPS ) = 0; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
168 virtual ArgToken make_conversion( BasicType type, klassOop tk, Bytecodes::Code op, ArgToken src, TRAPS ) = 0; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
169 virtual ArgToken make_fetch( BasicType type, klassOop tk, Bytecodes::Code op, ArgToken base, ArgToken offset, TRAPS ) = 0; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
170 virtual ArgToken make_invoke( methodOop m, vmIntrinsics::ID iid, Bytecodes::Code op, bool tailcall, int argc, ArgToken* argv, TRAPS ) = 0; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
171 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
172 // For make_invoke, the methodOop can be NULL if the intrinsic ID |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
173 // is something other than vmIntrinsics::_none. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
174 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
175 // and in case anyone cares to related the previous actions to the chain: |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
176 virtual void set_method_handle(oop mh) { } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
177 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
178 void lose(const char* msg, TRAPS) { chain().lose(msg, THREAD); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
179 const char* lose_message() { return chain().lose_message(); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
180 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
181 ArgToken walk(TRAPS); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
182 }; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
183 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
184 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
185 // An abstract interpreter for method handle chains. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
186 // Produces an account of the semantics of a chain, in terms of a static IR. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
187 // The IR happens to be JVM bytecodes. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
188 class MethodHandleCompiler : public MethodHandleWalker { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
189 private: |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
190 Thread* _thread; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
191 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
192 struct PrimCon { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
193 BasicType _type; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
194 jvalue _value; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
195 }; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
196 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
197 // Accumulated compiler state: |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
198 stringStream _bytes; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
199 GrowableArray<Handle> _constant_oops; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
200 GrowableArray<PrimCon*> _constant_prims; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
201 int _max_stack; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
202 int _num_params; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
203 int _max_locals; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
204 int _name_index; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
205 int _signature_index; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
206 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
207 // Stack values: |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
208 enum TokenType { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
209 tt_void, |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
210 tt_parameter, |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
211 tt_temporary, |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
212 tt_constant |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
213 }; |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
214 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
215 ArgToken make_stack_value(TokenType tt, BasicType type, int id) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
216 return ArgToken( ((intptr_t)id << 8) | ((intptr_t)type << 4) | (intptr_t)tt ); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
217 } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
218 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
219 public: |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
220 virtual ArgToken make_parameter(BasicType type, klassOop tk, int argnum, TRAPS) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
221 return make_stack_value(tt_parameter, type, argnum); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
222 } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
223 virtual ArgToken make_oop_constant(oop con, TRAPS) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
224 return make_stack_value(tt_constant, T_OBJECT, find_oop_constant(con)); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
225 } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
226 virtual ArgToken make_prim_constant(BasicType type, jvalue* con, TRAPS) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
227 return make_stack_value(tt_constant, type, find_prim_constant(type, con)); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
228 } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
229 virtual ArgToken make_conversion(BasicType type, klassOop tk, Bytecodes::Code op, ArgToken src, TRAPS); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
230 virtual ArgToken make_fetch(BasicType type, klassOop tk, Bytecodes::Code op, ArgToken base, ArgToken offset, TRAPS); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
231 virtual ArgToken make_invoke(methodOop m, vmIntrinsics::ID iid, Bytecodes::Code op, bool tailcall, int argc, ArgToken* argv, TRAPS); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
232 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
233 int find_oop_constant(oop con); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
234 int find_prim_constant(BasicType type, jvalue* con); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
235 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
236 public: |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
237 MethodHandleCompiler(Handle root, TRAPS) |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
238 : MethodHandleWalker(root, THREAD), |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
239 _thread(THREAD), |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
240 _bytes(50), |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
241 _constant_oops(THREAD, 10), |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
242 _constant_prims(THREAD, 10), |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
243 _max_stack(0), _max_locals(0), |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
244 _name_index(0), _signature_index(0) |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
245 { } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
246 const char* bytes() { return _bytes.as_string(); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
247 int constant_length() { return _constant_oops.length(); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
248 int max_stack() { return _max_stack; } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
249 int max_locals() { return _max_locals; } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
250 int name_index() { return _name_index; } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
251 int signature_index() { return _signature_index; } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
252 symbolHandle name() { return symbolHandle(_thread, (symbolOop)constant_oop_at(_name_index)()); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
253 symbolHandle signature() { return symbolHandle(_thread, (symbolOop)constant_oop_at(_signature_index)()); } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
254 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
255 bool constant_is_oop_at(int i) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
256 return (_constant_prims.at(i) == NULL); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
257 } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
258 Handle constant_oop_at(int i) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
259 assert(constant_is_oop_at(i), ""); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
260 return _constant_oops.at(i); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
261 } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
262 PrimCon* constant_prim_at(int i) { |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
263 assert(!constant_is_oop_at(i), ""); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
264 return _constant_prims.at(i); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
265 } |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
266 |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
267 // Compile the given MH chain into bytecode. |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
268 void compile(TRAPS); |
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
diff
changeset
|
269 }; |