0
|
1 /*
|
|
2 * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
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 class FastLockNode;
|
|
26 class FastUnlockNode;
|
342
|
27 class IdealKit;
|
0
|
28 class Parse;
|
|
29 class RootNode;
|
|
30
|
|
31 //-----------------------------------------------------------------------------
|
|
32 //----------------------------GraphKit-----------------------------------------
|
|
33 // Toolkit for building the common sorts of subgraphs.
|
|
34 // Does not know about bytecode parsing or type-flow results.
|
|
35 // It is able to create graphs implementing the semantics of most
|
|
36 // or all bytecodes, so that it can expand intrinsics and calls.
|
|
37 // It may depend on JVMState structure, but it must not depend
|
|
38 // on specific bytecode streams.
|
|
39 class GraphKit : public Phase {
|
|
40 friend class PreserveJVMState;
|
|
41
|
|
42 protected:
|
|
43 ciEnv* _env; // Compilation environment
|
|
44 PhaseGVN &_gvn; // Some optimizations while parsing
|
|
45 SafePointNode* _map; // Parser map from JVM to Nodes
|
|
46 SafePointNode* _exceptions;// Parser map(s) for exception state(s)
|
|
47 int _sp; // JVM Expression Stack Pointer
|
|
48 int _bci; // JVM Bytecode Pointer
|
|
49 ciMethod* _method; // JVM Current Method
|
|
50
|
|
51 private:
|
|
52 SafePointNode* map_not_null() const {
|
|
53 assert(_map != NULL, "must call stopped() to test for reset compiler map");
|
|
54 return _map;
|
|
55 }
|
|
56
|
|
57 public:
|
|
58 GraphKit(); // empty constructor
|
|
59 GraphKit(JVMState* jvms); // the JVM state on which to operate
|
|
60
|
|
61 #ifdef ASSERT
|
|
62 ~GraphKit() {
|
|
63 assert(!has_exceptions(), "user must call transfer_exceptions_into_jvms");
|
|
64 }
|
|
65 #endif
|
|
66
|
|
67 virtual Parse* is_Parse() const { return NULL; }
|
|
68
|
|
69 ciEnv* env() const { return _env; }
|
|
70 PhaseGVN& gvn() const { return _gvn; }
|
|
71
|
|
72 void record_for_igvn(Node* n) const { C->record_for_igvn(n); } // delegate to Compile
|
|
73
|
|
74 // Handy well-known nodes:
|
|
75 Node* null() const { return zerocon(T_OBJECT); }
|
|
76 Node* top() const { return C->top(); }
|
|
77 RootNode* root() const { return C->root(); }
|
|
78
|
|
79 // Create or find a constant node
|
|
80 Node* intcon(jint con) const { return _gvn.intcon(con); }
|
|
81 Node* longcon(jlong con) const { return _gvn.longcon(con); }
|
|
82 Node* makecon(const Type *t) const { return _gvn.makecon(t); }
|
|
83 Node* zerocon(BasicType bt) const { return _gvn.zerocon(bt); }
|
|
84 // (See also macro MakeConX in type.hpp, which uses intcon or longcon.)
|
|
85
|
|
86 jint find_int_con(Node* n, jint value_if_unknown) {
|
|
87 return _gvn.find_int_con(n, value_if_unknown);
|
|
88 }
|
|
89 jlong find_long_con(Node* n, jlong value_if_unknown) {
|
|
90 return _gvn.find_long_con(n, value_if_unknown);
|
|
91 }
|
|
92 // (See also macro find_intptr_t_con in type.hpp, which uses one of these.)
|
|
93
|
|
94 // JVM State accessors:
|
|
95 // Parser mapping from JVM indices into Nodes.
|
|
96 // Low slots are accessed by the StartNode::enum.
|
|
97 // Then come the locals at StartNode::Parms to StartNode::Parms+max_locals();
|
|
98 // Then come JVM stack slots.
|
|
99 // Finally come the monitors, if any.
|
|
100 // See layout accessors in class JVMState.
|
|
101
|
|
102 SafePointNode* map() const { return _map; }
|
|
103 bool has_exceptions() const { return _exceptions != NULL; }
|
|
104 JVMState* jvms() const { return map_not_null()->_jvms; }
|
|
105 int sp() const { return _sp; }
|
|
106 int bci() const { return _bci; }
|
|
107 Bytecodes::Code java_bc() const;
|
|
108 ciMethod* method() const { return _method; }
|
|
109
|
|
110 void set_jvms(JVMState* jvms) { set_map(jvms->map());
|
|
111 assert(jvms == this->jvms(), "sanity");
|
|
112 _sp = jvms->sp();
|
|
113 _bci = jvms->bci();
|
|
114 _method = jvms->has_method() ? jvms->method() : NULL; }
|
|
115 void set_map(SafePointNode* m) { _map = m; debug_only(verify_map()); }
|
|
116 void set_sp(int i) { assert(i >= 0, "must be non-negative"); _sp = i; }
|
|
117 void clean_stack(int from_sp); // clear garbage beyond from_sp to top
|
|
118
|
|
119 void inc_sp(int i) { set_sp(sp() + i); }
|
|
120 void set_bci(int bci) { _bci = bci; }
|
|
121
|
|
122 // Make sure jvms has current bci & sp.
|
|
123 JVMState* sync_jvms() const;
|
|
124 #ifdef ASSERT
|
|
125 // Make sure JVMS has an updated copy of bci and sp.
|
|
126 // Also sanity-check method, depth, and monitor depth.
|
|
127 bool jvms_in_sync() const;
|
|
128
|
|
129 // Make sure the map looks OK.
|
|
130 void verify_map() const;
|
|
131
|
|
132 // Make sure a proposed exception state looks OK.
|
|
133 static void verify_exception_state(SafePointNode* ex_map);
|
|
134 #endif
|
|
135
|
|
136 // Clone the existing map state. (Implements PreserveJVMState.)
|
|
137 SafePointNode* clone_map();
|
|
138
|
|
139 // Set the map to a clone of the given one.
|
|
140 void set_map_clone(SafePointNode* m);
|
|
141
|
|
142 // Tell if the compilation is failing.
|
|
143 bool failing() const { return C->failing(); }
|
|
144
|
|
145 // Set _map to NULL, signalling a stop to further bytecode execution.
|
|
146 // Preserve the map intact for future use, and return it back to the caller.
|
|
147 SafePointNode* stop() { SafePointNode* m = map(); set_map(NULL); return m; }
|
|
148
|
|
149 // Stop, but first smash the map's inputs to NULL, to mark it dead.
|
|
150 void stop_and_kill_map();
|
|
151
|
|
152 // Tell if _map is NULL, or control is top.
|
|
153 bool stopped();
|
|
154
|
|
155 // Tell if this method or any caller method has exception handlers.
|
|
156 bool has_ex_handler();
|
|
157
|
|
158 // Save an exception without blowing stack contents or other JVM state.
|
|
159 // (The extra pointer is stuck with add_req on the map, beyond the JVMS.)
|
|
160 static void set_saved_ex_oop(SafePointNode* ex_map, Node* ex_oop);
|
|
161
|
|
162 // Recover a saved exception from its map.
|
|
163 static Node* saved_ex_oop(SafePointNode* ex_map);
|
|
164
|
|
165 // Recover a saved exception from its map, and remove it from the map.
|
|
166 static Node* clear_saved_ex_oop(SafePointNode* ex_map);
|
|
167
|
|
168 #ifdef ASSERT
|
|
169 // Recover a saved exception from its map, and remove it from the map.
|
|
170 static bool has_saved_ex_oop(SafePointNode* ex_map);
|
|
171 #endif
|
|
172
|
|
173 // Push an exception in the canonical position for handlers (stack(0)).
|
|
174 void push_ex_oop(Node* ex_oop) {
|
|
175 ensure_stack(1); // ensure room to push the exception
|
|
176 set_stack(0, ex_oop);
|
|
177 set_sp(1);
|
|
178 clean_stack(1);
|
|
179 }
|
|
180
|
|
181 // Detach and return an exception state.
|
|
182 SafePointNode* pop_exception_state() {
|
|
183 SafePointNode* ex_map = _exceptions;
|
|
184 if (ex_map != NULL) {
|
|
185 _exceptions = ex_map->next_exception();
|
|
186 ex_map->set_next_exception(NULL);
|
|
187 debug_only(verify_exception_state(ex_map));
|
|
188 }
|
|
189 return ex_map;
|
|
190 }
|
|
191
|
|
192 // Add an exception, using the given JVM state, without commoning.
|
|
193 void push_exception_state(SafePointNode* ex_map) {
|
|
194 debug_only(verify_exception_state(ex_map));
|
|
195 ex_map->set_next_exception(_exceptions);
|
|
196 _exceptions = ex_map;
|
|
197 }
|
|
198
|
|
199 // Turn the current JVM state into an exception state, appending the ex_oop.
|
|
200 SafePointNode* make_exception_state(Node* ex_oop);
|
|
201
|
|
202 // Add an exception, using the given JVM state.
|
|
203 // Combine all exceptions with a common exception type into a single state.
|
|
204 // (This is done via combine_exception_states.)
|
|
205 void add_exception_state(SafePointNode* ex_map);
|
|
206
|
|
207 // Combine all exceptions of any sort whatever into a single master state.
|
|
208 SafePointNode* combine_and_pop_all_exception_states() {
|
|
209 if (_exceptions == NULL) return NULL;
|
|
210 SafePointNode* phi_map = pop_exception_state();
|
|
211 SafePointNode* ex_map;
|
|
212 while ((ex_map = pop_exception_state()) != NULL) {
|
|
213 combine_exception_states(ex_map, phi_map);
|
|
214 }
|
|
215 return phi_map;
|
|
216 }
|
|
217
|
|
218 // Combine the two exception states, building phis as necessary.
|
|
219 // The second argument is updated to include contributions from the first.
|
|
220 void combine_exception_states(SafePointNode* ex_map, SafePointNode* phi_map);
|
|
221
|
|
222 // Reset the map to the given state. If there are any half-finished phis
|
|
223 // in it (created by combine_exception_states), transform them now.
|
|
224 // Returns the exception oop. (Caller must call push_ex_oop if required.)
|
|
225 Node* use_exception_state(SafePointNode* ex_map);
|
|
226
|
|
227 // Collect exceptions from a given JVM state into my exception list.
|
|
228 void add_exception_states_from(JVMState* jvms);
|
|
229
|
|
230 // Collect all raised exceptions into the current JVM state.
|
|
231 // Clear the current exception list and map, returns the combined states.
|
|
232 JVMState* transfer_exceptions_into_jvms();
|
|
233
|
|
234 // Helper to throw a built-in exception.
|
|
235 // Range checks take the offending index.
|
|
236 // Cast and array store checks take the offending class.
|
|
237 // Others do not take the optional argument.
|
|
238 // The JVMS must allow the bytecode to be re-executed
|
|
239 // via an uncommon trap.
|
|
240 void builtin_throw(Deoptimization::DeoptReason reason, Node* arg = NULL);
|
|
241
|
|
242 // Helper Functions for adding debug information
|
|
243 void kill_dead_locals();
|
|
244 #ifdef ASSERT
|
|
245 bool dead_locals_are_killed();
|
|
246 #endif
|
|
247 // The call may deoptimize. Supply required JVM state as debug info.
|
|
248 // If must_throw is true, the call is guaranteed not to return normally.
|
|
249 void add_safepoint_edges(SafePointNode* call,
|
|
250 bool must_throw = false);
|
|
251
|
|
252 // How many stack inputs does the current BC consume?
|
|
253 // And, how does the stack change after the bytecode?
|
|
254 // Returns false if unknown.
|
|
255 bool compute_stack_effects(int& inputs, int& depth);
|
|
256
|
|
257 // Add a fixed offset to a pointer
|
|
258 Node* basic_plus_adr(Node* base, Node* ptr, intptr_t offset) {
|
|
259 return basic_plus_adr(base, ptr, MakeConX(offset));
|
|
260 }
|
|
261 Node* basic_plus_adr(Node* base, intptr_t offset) {
|
|
262 return basic_plus_adr(base, base, MakeConX(offset));
|
|
263 }
|
|
264 // Add a variable offset to a pointer
|
|
265 Node* basic_plus_adr(Node* base, Node* offset) {
|
|
266 return basic_plus_adr(base, base, offset);
|
|
267 }
|
|
268 Node* basic_plus_adr(Node* base, Node* ptr, Node* offset);
|
|
269
|
|
270 // Convert between int and long, and size_t.
|
|
271 // (See macros ConvI2X, etc., in type.hpp for ConvI2X, etc.)
|
|
272 Node* ConvI2L(Node* offset);
|
|
273 Node* ConvL2I(Node* offset);
|
|
274 // Find out the klass of an object.
|
|
275 Node* load_object_klass(Node* object);
|
|
276 // Find out the length of an array.
|
|
277 Node* load_array_length(Node* array);
|
|
278 // Helper function to do a NULL pointer check or ZERO check based on type.
|
|
279 Node* null_check_common(Node* value, BasicType type,
|
|
280 bool assert_null, Node* *null_control);
|
|
281 // Throw an exception if a given value is null.
|
|
282 // Return the value cast to not-null.
|
|
283 // Be clever about equivalent dominating null checks.
|
|
284 Node* do_null_check(Node* value, BasicType type) {
|
|
285 return null_check_common(value, type, false, NULL);
|
|
286 }
|
|
287 // Throw an uncommon trap if a given value is __not__ null.
|
|
288 // Return the value cast to null, and be clever about dominating checks.
|
|
289 Node* do_null_assert(Node* value, BasicType type) {
|
|
290 return null_check_common(value, type, true, NULL);
|
|
291 }
|
|
292 // Null check oop. Return null-path control into (*null_control).
|
|
293 // Return a cast-not-null node which depends on the not-null control.
|
|
294 // If never_see_null, use an uncommon trap (*null_control sees a top).
|
|
295 // The cast is not valid along the null path; keep a copy of the original.
|
|
296 Node* null_check_oop(Node* value, Node* *null_control,
|
|
297 bool never_see_null = false);
|
|
298
|
|
299 // Cast obj to not-null on this path
|
|
300 Node* cast_not_null(Node* obj, bool do_replace_in_map = true);
|
|
301 // Replace all occurrences of one node by another.
|
|
302 void replace_in_map(Node* old, Node* neww);
|
|
303
|
|
304 void push(Node* n) { map_not_null(); _map->set_stack(_map->_jvms,_sp++,n); }
|
|
305 Node* pop() { map_not_null(); return _map->stack(_map->_jvms,--_sp); }
|
|
306 Node* peek(int off=0) { map_not_null(); return _map->stack(_map->_jvms, _sp - off - 1); }
|
|
307
|
|
308 void push_pair(Node* ldval) {
|
|
309 push(ldval);
|
|
310 push(top()); // the halfword is merely a placeholder
|
|
311 }
|
|
312 void push_pair_local(int i) {
|
|
313 // longs are stored in locals in "push" order
|
|
314 push( local(i+0) ); // the real value
|
|
315 assert(local(i+1) == top(), "");
|
|
316 push(top()); // halfword placeholder
|
|
317 }
|
|
318 Node* pop_pair() {
|
|
319 // the second half is pushed last & popped first; it contains exactly nothing
|
|
320 Node* halfword = pop();
|
|
321 assert(halfword == top(), "");
|
|
322 // the long bits are pushed first & popped last:
|
|
323 return pop();
|
|
324 }
|
|
325 void set_pair_local(int i, Node* lval) {
|
|
326 // longs are stored in locals as a value/half pair (like doubles)
|
|
327 set_local(i+0, lval);
|
|
328 set_local(i+1, top());
|
|
329 }
|
|
330
|
|
331 // Push the node, which may be zero, one, or two words.
|
|
332 void push_node(BasicType n_type, Node* n) {
|
|
333 int n_size = type2size[n_type];
|
|
334 if (n_size == 1) push( n ); // T_INT, ...
|
|
335 else if (n_size == 2) push_pair( n ); // T_DOUBLE, T_LONG
|
|
336 else { assert(n_size == 0, "must be T_VOID"); }
|
|
337 }
|
|
338
|
|
339 Node* pop_node(BasicType n_type) {
|
|
340 int n_size = type2size[n_type];
|
|
341 if (n_size == 1) return pop();
|
|
342 else if (n_size == 2) return pop_pair();
|
|
343 else return NULL;
|
|
344 }
|
|
345
|
|
346 Node* control() const { return map_not_null()->control(); }
|
|
347 Node* i_o() const { return map_not_null()->i_o(); }
|
|
348 Node* returnadr() const { return map_not_null()->returnadr(); }
|
|
349 Node* frameptr() const { return map_not_null()->frameptr(); }
|
|
350 Node* local(uint idx) const { map_not_null(); return _map->local( _map->_jvms, idx); }
|
|
351 Node* stack(uint idx) const { map_not_null(); return _map->stack( _map->_jvms, idx); }
|
|
352 Node* argument(uint idx) const { map_not_null(); return _map->argument( _map->_jvms, idx); }
|
|
353 Node* monitor_box(uint idx) const { map_not_null(); return _map->monitor_box(_map->_jvms, idx); }
|
|
354 Node* monitor_obj(uint idx) const { map_not_null(); return _map->monitor_obj(_map->_jvms, idx); }
|
|
355
|
|
356 void set_control (Node* c) { map_not_null()->set_control(c); }
|
|
357 void set_i_o (Node* c) { map_not_null()->set_i_o(c); }
|
|
358 void set_local(uint idx, Node* c) { map_not_null(); _map->set_local( _map->_jvms, idx, c); }
|
|
359 void set_stack(uint idx, Node* c) { map_not_null(); _map->set_stack( _map->_jvms, idx, c); }
|
|
360 void set_argument(uint idx, Node* c){ map_not_null(); _map->set_argument(_map->_jvms, idx, c); }
|
|
361 void ensure_stack(uint stk_size) { map_not_null(); _map->ensure_stack(_map->_jvms, stk_size); }
|
|
362
|
|
363 // Access unaliased memory
|
|
364 Node* memory(uint alias_idx);
|
|
365 Node* memory(const TypePtr *tp) { return memory(C->get_alias_index(tp)); }
|
|
366 Node* memory(Node* adr) { return memory(_gvn.type(adr)->is_ptr()); }
|
|
367
|
|
368 // Access immutable memory
|
|
369 Node* immutable_memory() { return C->immutable_memory(); }
|
|
370
|
|
371 // Set unaliased memory
|
|
372 void set_memory(Node* c, uint alias_idx) { merged_memory()->set_memory_at(alias_idx, c); }
|
|
373 void set_memory(Node* c, const TypePtr *tp) { set_memory(c,C->get_alias_index(tp)); }
|
|
374 void set_memory(Node* c, Node* adr) { set_memory(c,_gvn.type(adr)->is_ptr()); }
|
|
375
|
|
376 // Get the entire memory state (probably a MergeMemNode), and reset it
|
|
377 // (The resetting prevents somebody from using the dangling Node pointer.)
|
|
378 Node* reset_memory();
|
|
379
|
|
380 // Get the entire memory state, asserted to be a MergeMemNode.
|
|
381 MergeMemNode* merged_memory() {
|
|
382 Node* mem = map_not_null()->memory();
|
|
383 assert(mem->is_MergeMem(), "parse memory is always pre-split");
|
|
384 return mem->as_MergeMem();
|
|
385 }
|
|
386
|
|
387 // Set the entire memory state; produce a new MergeMemNode.
|
|
388 void set_all_memory(Node* newmem);
|
|
389
|
|
390 // Create a memory projection from the call, then set_all_memory.
|
|
391 void set_all_memory_call(Node* call);
|
|
392
|
|
393 // Create a LoadNode, reading from the parser's memory state.
|
|
394 // (Note: require_atomic_access is useful only with T_LONG.)
|
|
395 Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt,
|
|
396 bool require_atomic_access = false) {
|
|
397 // This version computes alias_index from bottom_type
|
|
398 return make_load(ctl, adr, t, bt, adr->bottom_type()->is_ptr(),
|
|
399 require_atomic_access);
|
|
400 }
|
|
401 Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt, const TypePtr* adr_type, bool require_atomic_access = false) {
|
|
402 // This version computes alias_index from an address type
|
|
403 assert(adr_type != NULL, "use other make_load factory");
|
|
404 return make_load(ctl, adr, t, bt, C->get_alias_index(adr_type),
|
|
405 require_atomic_access);
|
|
406 }
|
|
407 // This is the base version which is given an alias index.
|
|
408 Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt, int adr_idx, bool require_atomic_access = false);
|
|
409
|
|
410 // Create & transform a StoreNode and store the effect into the
|
|
411 // parser's memory state.
|
|
412 Node* store_to_memory(Node* ctl, Node* adr, Node* val, BasicType bt,
|
|
413 const TypePtr* adr_type,
|
|
414 bool require_atomic_access = false) {
|
|
415 // This version computes alias_index from an address type
|
|
416 assert(adr_type != NULL, "use other store_to_memory factory");
|
|
417 return store_to_memory(ctl, adr, val, bt,
|
|
418 C->get_alias_index(adr_type),
|
|
419 require_atomic_access);
|
|
420 }
|
|
421 // This is the base version which is given alias index
|
|
422 // Return the new StoreXNode
|
|
423 Node* store_to_memory(Node* ctl, Node* adr, Node* val, BasicType bt,
|
|
424 int adr_idx,
|
|
425 bool require_atomic_access = false);
|
|
426
|
|
427
|
|
428 // All in one pre-barrier, store, post_barrier
|
|
429 // Insert a write-barrier'd store. This is to let generational GC
|
|
430 // work; we have to flag all oop-stores before the next GC point.
|
|
431 //
|
|
432 // It comes in 3 flavors of store to an object, array, or unknown.
|
|
433 // We use precise card marks for arrays to avoid scanning the entire
|
|
434 // array. We use imprecise for object. We use precise for unknown
|
|
435 // since we don't know if we have an array or and object or even
|
|
436 // where the object starts.
|
|
437 //
|
|
438 // If val==NULL, it is taken to be a completely unknown value. QQQ
|
|
439
|
|
440 Node* store_oop_to_object(Node* ctl,
|
|
441 Node* obj, // containing obj
|
|
442 Node* adr, // actual adress to store val at
|
|
443 const TypePtr* adr_type,
|
|
444 Node* val,
|
|
445 const Type* val_type,
|
|
446 BasicType bt);
|
|
447
|
|
448 Node* store_oop_to_array(Node* ctl,
|
|
449 Node* obj, // containing obj
|
|
450 Node* adr, // actual adress to store val at
|
|
451 const TypePtr* adr_type,
|
|
452 Node* val,
|
|
453 const Type* val_type,
|
|
454 BasicType bt);
|
|
455
|
|
456 // Could be an array or object we don't know at compile time (unsafe ref.)
|
|
457 Node* store_oop_to_unknown(Node* ctl,
|
|
458 Node* obj, // containing obj
|
|
459 Node* adr, // actual adress to store val at
|
|
460 const TypePtr* adr_type,
|
|
461 Node* val,
|
|
462 const Type* val_type,
|
|
463 BasicType bt);
|
|
464
|
|
465 // For the few case where the barriers need special help
|
|
466 void pre_barrier(Node* ctl, Node* obj, Node* adr, uint adr_idx,
|
|
467 Node* val, const Type* val_type, BasicType bt);
|
|
468
|
|
469 void post_barrier(Node* ctl, Node* store, Node* obj, Node* adr, uint adr_idx,
|
|
470 Node* val, BasicType bt, bool use_precise);
|
|
471
|
|
472 // Return addressing for an array element.
|
|
473 Node* array_element_address(Node* ary, Node* idx, BasicType elembt,
|
|
474 // Optional constraint on the array size:
|
|
475 const TypeInt* sizetype = NULL);
|
|
476
|
|
477 // Return a load of array element at idx.
|
|
478 Node* load_array_element(Node* ctl, Node* ary, Node* idx, const TypeAryPtr* arytype);
|
|
479
|
|
480 // CMS card-marks have an input from the corresponding oop_store
|
|
481 void cms_card_mark(Node* ctl, Node* adr, Node* val, Node* oop_store);
|
|
482
|
|
483 //---------------- Dtrace support --------------------
|
|
484 void make_dtrace_method_entry_exit(ciMethod* method, bool is_entry);
|
|
485 void make_dtrace_method_entry(ciMethod* method) {
|
|
486 make_dtrace_method_entry_exit(method, true);
|
|
487 }
|
|
488 void make_dtrace_method_exit(ciMethod* method) {
|
|
489 make_dtrace_method_entry_exit(method, false);
|
|
490 }
|
|
491
|
|
492 //--------------- stub generation -------------------
|
|
493 public:
|
|
494 void gen_stub(address C_function,
|
|
495 const char *name,
|
|
496 int is_fancy_jump,
|
|
497 bool pass_tls,
|
|
498 bool return_pc);
|
|
499
|
|
500 //---------- help for generating calls --------------
|
|
501
|
|
502 // Do a null check on the receiver, which is in argument(0).
|
|
503 Node* null_check_receiver(ciMethod* callee) {
|
|
504 assert(!callee->is_static(), "must be a virtual method");
|
|
505 int nargs = 1 + callee->signature()->size();
|
|
506 // Null check on self without removing any arguments. The argument
|
|
507 // null check technically happens in the wrong place, which can lead to
|
|
508 // invalid stack traces when the primitive is inlined into a method
|
|
509 // which handles NullPointerExceptions.
|
|
510 Node* receiver = argument(0);
|
|
511 _sp += nargs;
|
|
512 receiver = do_null_check(receiver, T_OBJECT);
|
|
513 _sp -= nargs;
|
|
514 return receiver;
|
|
515 }
|
|
516
|
|
517 // Fill in argument edges for the call from argument(0), argument(1), ...
|
|
518 // (The next step is to call set_edges_for_java_call.)
|
|
519 void set_arguments_for_java_call(CallJavaNode* call);
|
|
520
|
|
521 // Fill in non-argument edges for the call.
|
|
522 // Transform the call, and update the basics: control, i_o, memory.
|
|
523 // (The next step is usually to call set_results_for_java_call.)
|
|
524 void set_edges_for_java_call(CallJavaNode* call,
|
|
525 bool must_throw = false);
|
|
526
|
|
527 // Finish up a java call that was started by set_edges_for_java_call.
|
|
528 // Call add_exception on any throw arising from the call.
|
|
529 // Return the call result (transformed).
|
|
530 Node* set_results_for_java_call(CallJavaNode* call);
|
|
531
|
|
532 // Similar to set_edges_for_java_call, but simplified for runtime calls.
|
|
533 void set_predefined_output_for_runtime_call(Node* call) {
|
|
534 set_predefined_output_for_runtime_call(call, NULL, NULL);
|
|
535 }
|
|
536 void set_predefined_output_for_runtime_call(Node* call,
|
|
537 Node* keep_mem,
|
|
538 const TypePtr* hook_mem);
|
|
539 Node* set_predefined_input_for_runtime_call(SafePointNode* call);
|
|
540
|
|
541 // helper functions for statistics
|
|
542 void increment_counter(address counter_addr); // increment a debug counter
|
|
543 void increment_counter(Node* counter_addr); // increment a debug counter
|
|
544
|
|
545 // Bail out to the interpreter right now
|
|
546 // The optional klass is the one causing the trap.
|
|
547 // The optional reason is debug information written to the compile log.
|
|
548 // Optional must_throw is the same as with add_safepoint_edges.
|
|
549 void uncommon_trap(int trap_request,
|
|
550 ciKlass* klass = NULL, const char* reason_string = NULL,
|
|
551 bool must_throw = false, bool keep_exact_action = false);
|
|
552
|
|
553 // Shorthand, to avoid saying "Deoptimization::" so many times.
|
|
554 void uncommon_trap(Deoptimization::DeoptReason reason,
|
|
555 Deoptimization::DeoptAction action,
|
|
556 ciKlass* klass = NULL, const char* reason_string = NULL,
|
|
557 bool must_throw = false, bool keep_exact_action = false) {
|
|
558 uncommon_trap(Deoptimization::make_trap_request(reason, action),
|
|
559 klass, reason_string, must_throw, keep_exact_action);
|
|
560 }
|
|
561
|
|
562 // Report if there were too many traps at the current method and bci.
|
|
563 // Report if a trap was recorded, and/or PerMethodTrapLimit was exceeded.
|
|
564 // If there is no MDO at all, report no trap unless told to assume it.
|
|
565 bool too_many_traps(Deoptimization::DeoptReason reason) {
|
|
566 return C->too_many_traps(method(), bci(), reason);
|
|
567 }
|
|
568
|
|
569 // Report if there were too many recompiles at the current method and bci.
|
|
570 bool too_many_recompiles(Deoptimization::DeoptReason reason) {
|
|
571 return C->too_many_recompiles(method(), bci(), reason);
|
|
572 }
|
|
573
|
|
574 // vanilla/CMS post barrier
|
|
575 void write_barrier_post(Node *store, Node* obj, Node* adr, Node* val, bool use_precise);
|
|
576
|
|
577 // Returns the object (if any) which was created the moment before.
|
|
578 Node* just_allocated_object(Node* current_control);
|
|
579
|
|
580 static bool use_ReduceInitialCardMarks() {
|
|
581 return (ReduceInitialCardMarks
|
|
582 && Universe::heap()->can_elide_tlab_store_barriers());
|
|
583 }
|
|
584
|
342
|
585 // G1 pre/post barriers
|
|
586 void g1_write_barrier_pre(Node* obj,
|
|
587 Node* adr,
|
|
588 uint alias_idx,
|
|
589 Node* val,
|
|
590 const Type* val_type,
|
|
591 BasicType bt);
|
|
592
|
|
593 void g1_write_barrier_post(Node* store,
|
|
594 Node* obj,
|
|
595 Node* adr,
|
|
596 uint alias_idx,
|
|
597 Node* val,
|
|
598 BasicType bt,
|
|
599 bool use_precise);
|
|
600 // Helper function for g1
|
|
601 private:
|
|
602 void g1_mark_card(IdealKit* ideal, Node* card_adr, Node* store, Node* index, Node* index_adr,
|
|
603 Node* buffer, const TypeFunc* tf);
|
|
604
|
|
605 public:
|
0
|
606 // Helper function to round double arguments before a call
|
|
607 void round_double_arguments(ciMethod* dest_method);
|
|
608 void round_double_result(ciMethod* dest_method);
|
|
609
|
|
610 // rounding for strict float precision conformance
|
|
611 Node* precision_rounding(Node* n);
|
|
612
|
|
613 // rounding for strict double precision conformance
|
|
614 Node* dprecision_rounding(Node* n);
|
|
615
|
|
616 // rounding for non-strict double stores
|
|
617 Node* dstore_rounding(Node* n);
|
|
618
|
|
619 // Helper functions for fast/slow path codes
|
|
620 Node* opt_iff(Node* region, Node* iff);
|
|
621 Node* make_runtime_call(int flags,
|
|
622 const TypeFunc* call_type, address call_addr,
|
|
623 const char* call_name,
|
|
624 const TypePtr* adr_type, // NULL if no memory effects
|
|
625 Node* parm0 = NULL, Node* parm1 = NULL,
|
|
626 Node* parm2 = NULL, Node* parm3 = NULL,
|
|
627 Node* parm4 = NULL, Node* parm5 = NULL,
|
|
628 Node* parm6 = NULL, Node* parm7 = NULL);
|
|
629 enum { // flag values for make_runtime_call
|
|
630 RC_NO_FP = 1, // CallLeafNoFPNode
|
|
631 RC_NO_IO = 2, // do not hook IO edges
|
|
632 RC_NO_LEAF = 4, // CallStaticJavaNode
|
|
633 RC_MUST_THROW = 8, // flag passed to add_safepoint_edges
|
|
634 RC_NARROW_MEM = 16, // input memory is same as output
|
|
635 RC_UNCOMMON = 32, // freq. expected to be like uncommon trap
|
|
636 RC_LEAF = 0 // null value: no flags set
|
|
637 };
|
|
638
|
|
639 // merge in all memory slices from new_mem, along the given path
|
|
640 void merge_memory(Node* new_mem, Node* region, int new_path);
|
|
641 void make_slow_call_ex(Node* call, ciInstanceKlass* ex_klass, bool separate_io_proj);
|
|
642
|
|
643 // Helper functions to build synchronizations
|
|
644 int next_monitor();
|
|
645 Node* insert_mem_bar(int opcode, Node* precedent = NULL);
|
|
646 Node* insert_mem_bar_volatile(int opcode, int alias_idx, Node* precedent = NULL);
|
|
647 // Optional 'precedent' is appended as an extra edge, to force ordering.
|
|
648 FastLockNode* shared_lock(Node* obj);
|
|
649 void shared_unlock(Node* box, Node* obj);
|
|
650
|
|
651 // helper functions for the fast path/slow path idioms
|
|
652 Node* fast_and_slow(Node* in, const Type *result_type, Node* null_result, IfNode* fast_test, Node* fast_result, address slow_call, const TypeFunc *slow_call_type, Node* slow_arg, klassOop ex_klass, Node* slow_result);
|
|
653
|
|
654 // Generate an instance-of idiom. Used by both the instance-of bytecode
|
|
655 // and the reflective instance-of call.
|
|
656 Node* gen_instanceof( Node *subobj, Node* superkls );
|
|
657
|
|
658 // Generate a check-cast idiom. Used by both the check-cast bytecode
|
|
659 // and the array-store bytecode
|
|
660 Node* gen_checkcast( Node *subobj, Node* superkls,
|
|
661 Node* *failure_control = NULL );
|
|
662
|
|
663 // Generate a subtyping check. Takes as input the subtype and supertype.
|
|
664 // Returns 2 values: sets the default control() to the true path and
|
|
665 // returns the false path. Only reads from constant memory taken from the
|
|
666 // default memory; does not write anything. It also doesn't take in an
|
|
667 // Object; if you wish to check an Object you need to load the Object's
|
|
668 // class prior to coming here.
|
|
669 Node* gen_subtype_check(Node* subklass, Node* superklass);
|
|
670
|
|
671 // Static parse-time type checking logic for gen_subtype_check:
|
|
672 enum { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
|
|
673 int static_subtype_check(ciKlass* superk, ciKlass* subk);
|
|
674
|
|
675 // Exact type check used for predicted calls and casts.
|
|
676 // Rewrites (*casted_receiver) to be casted to the stronger type.
|
|
677 // (Caller is responsible for doing replace_in_map.)
|
|
678 Node* type_check_receiver(Node* receiver, ciKlass* klass, float prob,
|
|
679 Node* *casted_receiver);
|
|
680
|
|
681 // implementation of object creation
|
|
682 Node* set_output_for_allocation(AllocateNode* alloc,
|
|
683 const TypeOopPtr* oop_type,
|
|
684 bool raw_mem_only);
|
|
685 Node* get_layout_helper(Node* klass_node, jint& constant_value);
|
|
686 Node* new_instance(Node* klass_node,
|
|
687 Node* slow_test = NULL,
|
|
688 bool raw_mem_only = false,
|
|
689 Node* *return_size_val = NULL);
|
|
690 Node* new_array(Node* klass_node, Node* count_val,
|
|
691 bool raw_mem_only = false, Node* *return_size_val = NULL);
|
|
692
|
|
693 // Handy for making control flow
|
|
694 IfNode* create_and_map_if(Node* ctrl, Node* tst, float prob, float cnt) {
|
|
695 IfNode* iff = new (C, 2) IfNode(ctrl, tst, prob, cnt);// New IfNode's
|
|
696 _gvn.set_type(iff, iff->Value(&_gvn)); // Value may be known at parse-time
|
|
697 // Place 'if' on worklist if it will be in graph
|
|
698 if (!tst->is_Con()) record_for_igvn(iff); // Range-check and Null-check removal is later
|
|
699 return iff;
|
|
700 }
|
|
701
|
|
702 IfNode* create_and_xform_if(Node* ctrl, Node* tst, float prob, float cnt) {
|
|
703 IfNode* iff = new (C, 2) IfNode(ctrl, tst, prob, cnt);// New IfNode's
|
|
704 _gvn.transform(iff); // Value may be known at parse-time
|
|
705 // Place 'if' on worklist if it will be in graph
|
|
706 if (!tst->is_Con()) record_for_igvn(iff); // Range-check and Null-check removal is later
|
|
707 return iff;
|
|
708 }
|
|
709 };
|
|
710
|
|
711 // Helper class to support building of control flow branches. Upon
|
|
712 // creation the map and sp at bci are cloned and restored upon de-
|
|
713 // struction. Typical use:
|
|
714 //
|
|
715 // { PreserveJVMState pjvms(this);
|
|
716 // // code of new branch
|
|
717 // }
|
|
718 // // here the JVM state at bci is established
|
|
719
|
|
720 class PreserveJVMState: public StackObj {
|
|
721 protected:
|
|
722 GraphKit* _kit;
|
|
723 #ifdef ASSERT
|
|
724 int _block; // PO of current block, if a Parse
|
|
725 int _bci;
|
|
726 #endif
|
|
727 SafePointNode* _map;
|
|
728 uint _sp;
|
|
729
|
|
730 public:
|
|
731 PreserveJVMState(GraphKit* kit, bool clone_map = true);
|
|
732 ~PreserveJVMState();
|
|
733 };
|
|
734
|
|
735 // Helper class to build cutouts of the form if (p) ; else {x...}.
|
|
736 // The code {x...} must not fall through.
|
|
737 // The kit's main flow of control is set to the "then" continuation of if(p).
|
|
738 class BuildCutout: public PreserveJVMState {
|
|
739 public:
|
|
740 BuildCutout(GraphKit* kit, Node* p, float prob, float cnt = COUNT_UNKNOWN);
|
|
741 ~BuildCutout();
|
|
742 };
|