comparison src/share/vm/opto/graphKit.hpp @ 7194:beebba0acc11

7172640: C2: instrinsic implementations in LibraryCallKit should use argument() instead of pop() Reviewed-by: kvn, jrose
author twisti
date Mon, 26 Nov 2012 17:25:11 -0800
parents e626685e9f6c
children 29aa8936f03c
comparison
equal deleted inserted replaced
7193:ee32440febeb 7194:beebba0acc11
39 #include "runtime/deoptimization.hpp" 39 #include "runtime/deoptimization.hpp"
40 40
41 class FastLockNode; 41 class FastLockNode;
42 class FastUnlockNode; 42 class FastUnlockNode;
43 class IdealKit; 43 class IdealKit;
44 class LibraryCallKit;
44 class Parse; 45 class Parse;
45 class RootNode; 46 class RootNode;
46 47
47 //----------------------------------------------------------------------------- 48 //-----------------------------------------------------------------------------
48 //----------------------------GraphKit----------------------------------------- 49 //----------------------------GraphKit-----------------------------------------
58 protected: 59 protected:
59 ciEnv* _env; // Compilation environment 60 ciEnv* _env; // Compilation environment
60 PhaseGVN &_gvn; // Some optimizations while parsing 61 PhaseGVN &_gvn; // Some optimizations while parsing
61 SafePointNode* _map; // Parser map from JVM to Nodes 62 SafePointNode* _map; // Parser map from JVM to Nodes
62 SafePointNode* _exceptions;// Parser map(s) for exception state(s) 63 SafePointNode* _exceptions;// Parser map(s) for exception state(s)
63 int _sp; // JVM Expression Stack Pointer
64 int _bci; // JVM Bytecode Pointer 64 int _bci; // JVM Bytecode Pointer
65 ciMethod* _method; // JVM Current Method 65 ciMethod* _method; // JVM Current Method
66
67 private:
68 int _sp; // JVM Expression Stack Pointer; don't modify directly!
66 69
67 private: 70 private:
68 SafePointNode* map_not_null() const { 71 SafePointNode* map_not_null() const {
69 assert(_map != NULL, "must call stopped() to test for reset compiler map"); 72 assert(_map != NULL, "must call stopped() to test for reset compiler map");
70 return _map; 73 return _map;
78 ~GraphKit() { 81 ~GraphKit() {
79 assert(!has_exceptions(), "user must call transfer_exceptions_into_jvms"); 82 assert(!has_exceptions(), "user must call transfer_exceptions_into_jvms");
80 } 83 }
81 #endif 84 #endif
82 85
83 virtual Parse* is_Parse() const { return NULL; } 86 virtual Parse* is_Parse() const { return NULL; }
87 virtual LibraryCallKit* is_LibraryCallKit() const { return NULL; }
84 88
85 ciEnv* env() const { return _env; } 89 ciEnv* env() const { return _env; }
86 PhaseGVN& gvn() const { return _gvn; } 90 PhaseGVN& gvn() const { return _gvn; }
87 91
88 void record_for_igvn(Node* n) const { C->record_for_igvn(n); } // delegate to Compile 92 void record_for_igvn(Node* n) const { C->record_for_igvn(n); } // delegate to Compile
139 assert(jvms == this->jvms(), "sanity"); 143 assert(jvms == this->jvms(), "sanity");
140 _sp = jvms->sp(); 144 _sp = jvms->sp();
141 _bci = jvms->bci(); 145 _bci = jvms->bci();
142 _method = jvms->has_method() ? jvms->method() : NULL; } 146 _method = jvms->has_method() ? jvms->method() : NULL; }
143 void set_map(SafePointNode* m) { _map = m; debug_only(verify_map()); } 147 void set_map(SafePointNode* m) { _map = m; debug_only(verify_map()); }
144 void set_sp(int i) { assert(i >= 0, "must be non-negative"); _sp = i; } 148 void set_sp(int sp) { assert(sp >= 0, err_msg_res("sp must be non-negative: %d", sp)); _sp = sp; }
145 void clean_stack(int from_sp); // clear garbage beyond from_sp to top 149 void clean_stack(int from_sp); // clear garbage beyond from_sp to top
146 150
147 void inc_sp(int i) { set_sp(sp() + i); } 151 void inc_sp(int i) { set_sp(sp() + i); }
148 void dec_sp(int i) { set_sp(sp() - i); } 152 void dec_sp(int i) { set_sp(sp() - i); }
149 void set_bci(int bci) { _bci = bci; } 153 void set_bci(int bci) { _bci = bci; }
150 154
151 // Make sure jvms has current bci & sp. 155 // Make sure jvms has current bci & sp.
152 JVMState* sync_jvms() const; 156 JVMState* sync_jvms() const;
157 JVMState* sync_jvms_for_reexecute();
158
153 #ifdef ASSERT 159 #ifdef ASSERT
154 // Make sure JVMS has an updated copy of bci and sp. 160 // Make sure JVMS has an updated copy of bci and sp.
155 // Also sanity-check method, depth, and monitor depth. 161 // Also sanity-check method, depth, and monitor depth.
156 bool jvms_in_sync() const; 162 bool jvms_in_sync() const;
157 163
284 bool must_throw = false); 290 bool must_throw = false);
285 291
286 // How many stack inputs does the current BC consume? 292 // How many stack inputs does the current BC consume?
287 // And, how does the stack change after the bytecode? 293 // And, how does the stack change after the bytecode?
288 // Returns false if unknown. 294 // Returns false if unknown.
289 bool compute_stack_effects(int& inputs, int& depth, bool for_parse = false); 295 bool compute_stack_effects(int& inputs, int& depth);
290 296
291 // Add a fixed offset to a pointer 297 // Add a fixed offset to a pointer
292 Node* basic_plus_adr(Node* base, Node* ptr, intptr_t offset) { 298 Node* basic_plus_adr(Node* base, Node* ptr, intptr_t offset) {
293 return basic_plus_adr(base, ptr, MakeConX(offset)); 299 return basic_plus_adr(base, ptr, MakeConX(offset));
294 } 300 }
335 Node* ConvL2I(Node* offset); 341 Node* ConvL2I(Node* offset);
336 // Find out the klass of an object. 342 // Find out the klass of an object.
337 Node* load_object_klass(Node* object); 343 Node* load_object_klass(Node* object);
338 // Find out the length of an array. 344 // Find out the length of an array.
339 Node* load_array_length(Node* array); 345 Node* load_array_length(Node* array);
346
347
340 // Helper function to do a NULL pointer check or ZERO check based on type. 348 // Helper function to do a NULL pointer check or ZERO check based on type.
341 Node* null_check_common(Node* value, BasicType type,
342 bool assert_null, Node* *null_control);
343 // Throw an exception if a given value is null. 349 // Throw an exception if a given value is null.
344 // Return the value cast to not-null. 350 // Return the value cast to not-null.
345 // Be clever about equivalent dominating null checks. 351 // Be clever about equivalent dominating null checks.
346 Node* do_null_check(Node* value, BasicType type) { 352 Node* null_check_common(Node* value, BasicType type,
347 return null_check_common(value, type, false, NULL); 353 bool assert_null = false, Node* *null_control = NULL);
354 Node* null_check(Node* value, BasicType type = T_OBJECT) {
355 return null_check_common(value, type);
356 }
357 Node* null_check_receiver() {
358 assert(argument(0)->bottom_type()->isa_ptr(), "must be");
359 return null_check(argument(0));
360 }
361 Node* zero_check_int(Node* value) {
362 assert(value->bottom_type()->basic_type() == T_INT,
363 err_msg_res("wrong type: %s", type2name(value->bottom_type()->basic_type())));
364 return null_check_common(value, T_INT);
365 }
366 Node* zero_check_long(Node* value) {
367 assert(value->bottom_type()->basic_type() == T_LONG,
368 err_msg_res("wrong type: %s", type2name(value->bottom_type()->basic_type())));
369 return null_check_common(value, T_LONG);
348 } 370 }
349 // Throw an uncommon trap if a given value is __not__ null. 371 // Throw an uncommon trap if a given value is __not__ null.
350 // Return the value cast to null, and be clever about dominating checks. 372 // Return the value cast to null, and be clever about dominating checks.
351 Node* do_null_assert(Node* value, BasicType type) { 373 Node* null_assert(Node* value, BasicType type = T_OBJECT) {
352 return null_check_common(value, type, true, NULL); 374 return null_check_common(value, type, true);
353 } 375 }
376
354 // Null check oop. Return null-path control into (*null_control). 377 // Null check oop. Return null-path control into (*null_control).
355 // Return a cast-not-null node which depends on the not-null control. 378 // Return a cast-not-null node which depends on the not-null control.
356 // If never_see_null, use an uncommon trap (*null_control sees a top). 379 // If never_see_null, use an uncommon trap (*null_control sees a top).
357 // The cast is not valid along the null path; keep a copy of the original. 380 // The cast is not valid along the null path; keep a copy of the original.
358 Node* null_check_oop(Node* value, Node* *null_control, 381 Node* null_check_oop(Node* value, Node* *null_control,
369 // Cast obj to not-null on this path 392 // Cast obj to not-null on this path
370 Node* cast_not_null(Node* obj, bool do_replace_in_map = true); 393 Node* cast_not_null(Node* obj, bool do_replace_in_map = true);
371 // Replace all occurrences of one node by another. 394 // Replace all occurrences of one node by another.
372 void replace_in_map(Node* old, Node* neww); 395 void replace_in_map(Node* old, Node* neww);
373 396
374 void push(Node* n) { map_not_null(); _map->set_stack(_map->_jvms, _sp++, n); } 397 void push(Node* n) { map_not_null(); _map->set_stack(_map->_jvms, _sp++ , n); }
375 Node* pop() { map_not_null(); return _map->stack( _map->_jvms, --_sp); } 398 Node* pop() { map_not_null(); return _map->stack( _map->_jvms, --_sp ); }
376 Node* peek(int off = 0) { map_not_null(); return _map->stack( _map->_jvms, _sp - off - 1); } 399 Node* peek(int off = 0) { map_not_null(); return _map->stack( _map->_jvms, _sp - off - 1 ); }
377 400
378 void push_pair(Node* ldval) { 401 void push_pair(Node* ldval) {
379 push(ldval); 402 push(ldval);
380 push(top()); // the halfword is merely a placeholder 403 push(top()); // the halfword is merely a placeholder
381 } 404 }
578 bool pass_tls, 601 bool pass_tls,
579 bool return_pc); 602 bool return_pc);
580 603
581 //---------- help for generating calls -------------- 604 //---------- help for generating calls --------------
582 605
583 // Do a null check on the receiver, which is in argument(0). 606 // Do a null check on the receiver as it would happen before the call to
584 Node* null_check_receiver(ciMethod* callee) { 607 // callee (with all arguments still on the stack).
608 Node* null_check_receiver_before_call(ciMethod* callee) {
585 assert(!callee->is_static(), "must be a virtual method"); 609 assert(!callee->is_static(), "must be a virtual method");
586 int nargs = 1 + callee->signature()->size(); 610 const int nargs = callee->arg_size();
587 // Null check on self without removing any arguments. The argument 611 inc_sp(nargs);
588 // null check technically happens in the wrong place, which can lead to 612 Node* n = null_check_receiver();
589 // invalid stack traces when the primitive is inlined into a method 613 dec_sp(nargs);
590 // which handles NullPointerExceptions. 614 return n;
591 Node* receiver = argument(0);
592 _sp += nargs;
593 receiver = do_null_check(receiver, T_OBJECT);
594 _sp -= nargs;
595 return receiver;
596 } 615 }
597 616
598 // Fill in argument edges for the call from argument(0), argument(1), ... 617 // Fill in argument edges for the call from argument(0), argument(1), ...
599 // (The next step is to call set_edges_for_java_call.) 618 // (The next step is to call set_edges_for_java_call.)
600 void set_arguments_for_java_call(CallJavaNode* call); 619 void set_arguments_for_java_call(CallJavaNode* call);
642 ciKlass* klass = NULL, const char* reason_string = NULL, 661 ciKlass* klass = NULL, const char* reason_string = NULL,
643 bool must_throw = false, bool keep_exact_action = false) { 662 bool must_throw = false, bool keep_exact_action = false) {
644 uncommon_trap(Deoptimization::make_trap_request(reason, action), 663 uncommon_trap(Deoptimization::make_trap_request(reason, action),
645 klass, reason_string, must_throw, keep_exact_action); 664 klass, reason_string, must_throw, keep_exact_action);
646 } 665 }
666
667 // SP when bytecode needs to be reexecuted.
668 virtual int reexecute_sp() { return sp(); }
647 669
648 // Report if there were too many traps at the current method and bci. 670 // Report if there were too many traps at the current method and bci.
649 // Report if a trap was recorded, and/or PerMethodTrapLimit was exceeded. 671 // Report if a trap was recorded, and/or PerMethodTrapLimit was exceeded.
650 // If there is no MDO at all, report no trap unless told to assume it. 672 // If there is no MDO at all, report no trap unless told to assume it.
651 bool too_many_traps(Deoptimization::DeoptReason reason) { 673 bool too_many_traps(Deoptimization::DeoptReason reason) {