563 if (treat_throw_as_hot
564 && (!StackTraceInThrowable || OmitStackTraceInFastThrow)) {
565 // If the throw is local, we use a pre-existing instance and
566 // punt on the backtrace. This would lead to a missing backtrace
567 // (a repeat of 4292742) if the backtrace object is ever asked
568 // for its backtrace.
569 // Fixing this remaining case of 4292742 requires some flavor of
570 // escape analysis. Leave that for the future.
571 ciInstance* ex_obj = NULL;
572 switch (reason) {
573 case Deoptimization::Reason_null_check:
574 ex_obj = env()->NullPointerException_instance();
575 break;
576 case Deoptimization::Reason_div0_check:
577 ex_obj = env()->ArithmeticException_instance();
578 break;
579 case Deoptimization::Reason_range_check:
580 ex_obj = env()->ArrayIndexOutOfBoundsException_instance();
581 break;
582 case Deoptimization::Reason_class_check:
583 if (java_bc() == Bytecodes::_aastore) {
584 ex_obj = env()->ArrayStoreException_instance();
585 } else {
586 ex_obj = env()->ClassCastException_instance();
587 }
588 break;
589 }
590 if (failing()) { stop(); return; } // exception allocation might fail
591 if (ex_obj != NULL) {
592 // Cheat with a preallocated exception object.
593 if (C->log() != NULL)
594 C->log()->elem("hot_throw preallocated='1' reason='%s'",
595 Deoptimization::trap_reason_name(reason));
596 const TypeInstPtr* ex_con = TypeInstPtr::make(ex_obj);
597 Node* ex_node = _gvn.transform(ConNode::make(ex_con));
598
599 // Clear the detail message of the preallocated exception object.
600 // Weblogic sometimes mutates the detail message of exceptions
601 // using reflection.
602 int offset = java_lang_Throwable::get_detailMessage_offset();
603 const TypePtr* adr_typ = ex_con->add_offset(offset);
2624 // The decision to inline or out-of-line this final check is platform
2625 // dependent, and is found in the AD file definition of PartialSubtypeCheck.
2626 Node* psc = gvn->transform(
2627 new PartialSubtypeCheckNode(*ctrl, subklass, superklass));
2628
2629 IfNode *iff4 = gen_subtype_check_compare(*ctrl, psc, gvn->zerocon(T_OBJECT), BoolTest::ne, PROB_FAIR, gvn, T_ADDRESS);
2630 r_not_subtype->init_req(2, gvn->transform(new IfTrueNode (iff4)));
2631 r_ok_subtype ->init_req(3, gvn->transform(new IfFalseNode(iff4)));
2632
2633 // Return false path; set default control to true path.
2634 *ctrl = gvn->transform(r_ok_subtype);
2635 return gvn->transform(r_not_subtype);
2636 }
2637
2638 // Profile-driven exact type check:
2639 Node* GraphKit::type_check_receiver(Node* receiver, ciKlass* klass,
2640 float prob,
2641 Node* *casted_receiver) {
2642 const TypeKlassPtr* tklass = TypeKlassPtr::make(klass);
2643 Node* recv_klass = load_object_klass(receiver);
2644 Node* want_klass = makecon(tklass);
2645 Node* cmp = _gvn.transform( new CmpPNode(recv_klass, want_klass) );
2646 Node* bol = _gvn.transform( new BoolNode(cmp, BoolTest::eq) );
2647 IfNode* iff = create_and_xform_if(control(), bol, prob, COUNT_UNKNOWN);
2648 set_control( _gvn.transform( new IfTrueNode (iff) ));
2649 Node* fail = _gvn.transform( new IfFalseNode(iff) );
2650
2651 const TypeOopPtr* recv_xtype = tklass->as_instance_type();
2652 assert(recv_xtype->klass_is_exact(), "");
2653
2654 // Subsume downstream occurrences of receiver with a cast to
2655 // recv_xtype, since now we know what the type will be.
2656 Node* cast = new CheckCastPPNode(control(), receiver, recv_xtype);
2657 (*casted_receiver) = _gvn.transform(cast);
2658 // (User must make the replace_in_map call.)
2659
2660 return fail;
2661 }
2662
2663
2664 //------------------------------seems_never_null-------------------------------
2665 // Use null_seen information if it is available from the profile.
2666 // If we see an unexpected null at a type check we record it and force a
2667 // recompile; the offending check will be recompiled to handle NULLs.
2668 // If we see several offending BCIs, then all checks in the
2669 // method will be recompiled.
2670 bool GraphKit::seems_never_null(Node* obj, ciProfileData* data, bool& speculating) {
2671 speculating = !_gvn.type(obj)->speculative_maybe_null();
2672 Deoptimization::DeoptReason reason = Deoptimization::reason_null_check(speculating);
2673 if (UncommonNullCast // Cutout for this technique
2674 && obj != null() // And not the -Xcomp stupid case?
2675 && !too_many_traps(reason)
2676 ) {
2677 if (speculating) {
2678 return true;
2679 }
2680 if (data == NULL)
2681 // Edge case: no mature data. Be optimistic here.
2682 return true;
3380 const TypeKlassPtr* tklass = _gvn.type(klass_node)->isa_klassptr();
3381 if (!tklass) tklass = TypeKlassPtr::OBJECT;
3382 const TypeOopPtr* oop_type = tklass->as_instance_type();
3383
3384 // Now generate allocation code
3385
3386 // The entire memory state is needed for slow path of the allocation
3387 // since GC and deoptimization can happen.
3388 Node *mem = reset_memory();
3389 set_all_memory(mem); // Create new memory state
3390
3391 AllocateNode* alloc = new AllocateNode(C, AllocateNode::alloc_type(Type::TOP),
3392 control(), mem, i_o(),
3393 size, klass_node,
3394 initial_slow_test);
3395
3396 return set_output_for_allocation(alloc, oop_type, deoptimize_on_exception);
3397 }
3398
3399 //-------------------------------new_array-------------------------------------
3400 // helper for newarray, anewarray and vnewarray
3401 // The 'length' parameter is (obviously) the length of the array.
3402 // See comments on new_instance for the meaning of the other arguments.
3403 Node* GraphKit::new_array(Node* klass_node, // array klass (maybe variable)
3404 Node* length, // number of array elements
3405 int nargs, // number of arguments to push back for uncommon trap
3406 Node* *return_size_val,
3407 bool deoptimize_on_exception) {
3408 jint layout_con = Klass::_lh_neutral_value;
3409 Node* layout_val = get_layout_helper(klass_node, layout_con);
3410 int layout_is_con = (layout_val == NULL);
3411
3412 if (!layout_is_con && !StressReflectiveCode &&
3413 !too_many_traps(Deoptimization::Reason_class_check)) {
3414 // This is a reflective array creation site.
3415 // Optimistically assume that it is a subtype of Object[],
3416 // so that we can fold up all the address arithmetic.
3417 layout_con = Klass::array_layout_helper(T_OBJECT);
3418 Node* cmp_lh = _gvn.transform( new CmpINode(layout_val, intcon(layout_con)) );
3419 Node* bol_lh = _gvn.transform( new BoolNode(cmp_lh, BoolTest::eq) );
3420 { BuildCutout unless(this, bol_lh, PROB_MAX);
|
563 if (treat_throw_as_hot
564 && (!StackTraceInThrowable || OmitStackTraceInFastThrow)) {
565 // If the throw is local, we use a pre-existing instance and
566 // punt on the backtrace. This would lead to a missing backtrace
567 // (a repeat of 4292742) if the backtrace object is ever asked
568 // for its backtrace.
569 // Fixing this remaining case of 4292742 requires some flavor of
570 // escape analysis. Leave that for the future.
571 ciInstance* ex_obj = NULL;
572 switch (reason) {
573 case Deoptimization::Reason_null_check:
574 ex_obj = env()->NullPointerException_instance();
575 break;
576 case Deoptimization::Reason_div0_check:
577 ex_obj = env()->ArithmeticException_instance();
578 break;
579 case Deoptimization::Reason_range_check:
580 ex_obj = env()->ArrayIndexOutOfBoundsException_instance();
581 break;
582 case Deoptimization::Reason_class_check:
583 if (java_bc() == Bytecodes::_aastore || java_bc() == Bytecodes::_vastore) {
584 ex_obj = env()->ArrayStoreException_instance();
585 } else {
586 ex_obj = env()->ClassCastException_instance();
587 }
588 break;
589 }
590 if (failing()) { stop(); return; } // exception allocation might fail
591 if (ex_obj != NULL) {
592 // Cheat with a preallocated exception object.
593 if (C->log() != NULL)
594 C->log()->elem("hot_throw preallocated='1' reason='%s'",
595 Deoptimization::trap_reason_name(reason));
596 const TypeInstPtr* ex_con = TypeInstPtr::make(ex_obj);
597 Node* ex_node = _gvn.transform(ConNode::make(ex_con));
598
599 // Clear the detail message of the preallocated exception object.
600 // Weblogic sometimes mutates the detail message of exceptions
601 // using reflection.
602 int offset = java_lang_Throwable::get_detailMessage_offset();
603 const TypePtr* adr_typ = ex_con->add_offset(offset);
2624 // The decision to inline or out-of-line this final check is platform
2625 // dependent, and is found in the AD file definition of PartialSubtypeCheck.
2626 Node* psc = gvn->transform(
2627 new PartialSubtypeCheckNode(*ctrl, subklass, superklass));
2628
2629 IfNode *iff4 = gen_subtype_check_compare(*ctrl, psc, gvn->zerocon(T_OBJECT), BoolTest::ne, PROB_FAIR, gvn, T_ADDRESS);
2630 r_not_subtype->init_req(2, gvn->transform(new IfTrueNode (iff4)));
2631 r_ok_subtype ->init_req(3, gvn->transform(new IfFalseNode(iff4)));
2632
2633 // Return false path; set default control to true path.
2634 *ctrl = gvn->transform(r_ok_subtype);
2635 return gvn->transform(r_not_subtype);
2636 }
2637
2638 // Profile-driven exact type check:
2639 Node* GraphKit::type_check_receiver(Node* receiver, ciKlass* klass,
2640 float prob,
2641 Node* *casted_receiver) {
2642 const TypeKlassPtr* tklass = TypeKlassPtr::make(klass);
2643 Node* recv_klass = load_object_klass(receiver);
2644 Node* fail = type_check(recv_klass, tklass, prob);
2645 const TypeOopPtr* recv_xtype = tklass->as_instance_type();
2646 assert(recv_xtype->klass_is_exact(), "");
2647
2648 // Subsume downstream occurrences of receiver with a cast to
2649 // recv_xtype, since now we know what the type will be.
2650 Node* cast = new CheckCastPPNode(control(), receiver, recv_xtype);
2651 (*casted_receiver) = _gvn.transform(cast);
2652 // (User must make the replace_in_map call.)
2653
2654 return fail;
2655 }
2656
2657 Node* GraphKit::type_check(Node* recv_klass, const TypeKlassPtr* tklass,
2658 float prob) {
2659 //const TypeKlassPtr* tklass = TypeKlassPtr::make(klass);
2660 Node* want_klass = makecon(tklass);
2661 Node* cmp = _gvn.transform( new CmpPNode(recv_klass, want_klass));
2662 Node* bol = _gvn.transform( new BoolNode(cmp, BoolTest::eq) );
2663 IfNode* iff = create_and_xform_if(control(), bol, prob, COUNT_UNKNOWN);
2664 set_control( _gvn.transform( new IfTrueNode (iff)));
2665 Node* fail = _gvn.transform( new IfFalseNode(iff));
2666 return fail;
2667 }
2668
2669
2670 //------------------------------seems_never_null-------------------------------
2671 // Use null_seen information if it is available from the profile.
2672 // If we see an unexpected null at a type check we record it and force a
2673 // recompile; the offending check will be recompiled to handle NULLs.
2674 // If we see several offending BCIs, then all checks in the
2675 // method will be recompiled.
2676 bool GraphKit::seems_never_null(Node* obj, ciProfileData* data, bool& speculating) {
2677 speculating = !_gvn.type(obj)->speculative_maybe_null();
2678 Deoptimization::DeoptReason reason = Deoptimization::reason_null_check(speculating);
2679 if (UncommonNullCast // Cutout for this technique
2680 && obj != null() // And not the -Xcomp stupid case?
2681 && !too_many_traps(reason)
2682 ) {
2683 if (speculating) {
2684 return true;
2685 }
2686 if (data == NULL)
2687 // Edge case: no mature data. Be optimistic here.
2688 return true;
3386 const TypeKlassPtr* tklass = _gvn.type(klass_node)->isa_klassptr();
3387 if (!tklass) tklass = TypeKlassPtr::OBJECT;
3388 const TypeOopPtr* oop_type = tklass->as_instance_type();
3389
3390 // Now generate allocation code
3391
3392 // The entire memory state is needed for slow path of the allocation
3393 // since GC and deoptimization can happen.
3394 Node *mem = reset_memory();
3395 set_all_memory(mem); // Create new memory state
3396
3397 AllocateNode* alloc = new AllocateNode(C, AllocateNode::alloc_type(Type::TOP),
3398 control(), mem, i_o(),
3399 size, klass_node,
3400 initial_slow_test);
3401
3402 return set_output_for_allocation(alloc, oop_type, deoptimize_on_exception);
3403 }
3404
3405 //-------------------------------new_array-------------------------------------
3406 // helper for newarray and anewarray
3407 // The 'length' parameter is (obviously) the length of the array.
3408 // See comments on new_instance for the meaning of the other arguments.
3409 Node* GraphKit::new_array(Node* klass_node, // array klass (maybe variable)
3410 Node* length, // number of array elements
3411 int nargs, // number of arguments to push back for uncommon trap
3412 Node* *return_size_val,
3413 bool deoptimize_on_exception) {
3414 jint layout_con = Klass::_lh_neutral_value;
3415 Node* layout_val = get_layout_helper(klass_node, layout_con);
3416 int layout_is_con = (layout_val == NULL);
3417
3418 if (!layout_is_con && !StressReflectiveCode &&
3419 !too_many_traps(Deoptimization::Reason_class_check)) {
3420 // This is a reflective array creation site.
3421 // Optimistically assume that it is a subtype of Object[],
3422 // so that we can fold up all the address arithmetic.
3423 layout_con = Klass::array_layout_helper(T_OBJECT);
3424 Node* cmp_lh = _gvn.transform( new CmpINode(layout_val, intcon(layout_con)) );
3425 Node* bol_lh = _gvn.transform( new BoolNode(cmp_lh, BoolTest::eq) );
3426 { BuildCutout unless(this, bol_lh, PROB_MAX);
|