761 @Hidden 762 @Override 763 protected MethodHandle getTarget() { 764 return target; 765 } 766 767 @Override 768 public MethodHandle asTypeUncached(MethodType newType) { 769 MethodHandle newTarget = target.asType(newType); 770 MethodHandle wrapper; 771 if (isCounting) { 772 LambdaForm lform; 773 lform = countingFormProducer.apply(newTarget); 774 wrapper = new CountingWrapper(newTarget, lform, countingFormProducer, nonCountingFormProducer, DONT_INLINE_THRESHOLD); 775 } else { 776 wrapper = newTarget; // no need for a counting wrapper anymore 777 } 778 return (asTypeCache = wrapper); 779 } 780 781 boolean countDown() { 782 int c = count; 783 if (c <= 1) { 784 // Try to limit number of updates. MethodHandle.updateForm() doesn't guarantee LF update visibility. 785 if (isCounting) { 786 isCounting = false; 787 return true; 788 } else { 789 return false; 790 } 791 } else { 792 count = c - 1; 793 return false; 794 } 795 } 796 797 @Hidden 798 static void maybeStopCounting(Object o1) { 799 CountingWrapper wrapper = (CountingWrapper) o1; 800 if (wrapper.countDown()) { 801 // Reached invocation threshold. Replace counting behavior with a non-counting one. 802 LambdaForm lform = wrapper.nonCountingFormProducer.apply(wrapper.target); | 761 @Hidden 762 @Override 763 protected MethodHandle getTarget() { 764 return target; 765 } 766 767 @Override 768 public MethodHandle asTypeUncached(MethodType newType) { 769 MethodHandle newTarget = target.asType(newType); 770 MethodHandle wrapper; 771 if (isCounting) { 772 LambdaForm lform; 773 lform = countingFormProducer.apply(newTarget); 774 wrapper = new CountingWrapper(newTarget, lform, countingFormProducer, nonCountingFormProducer, DONT_INLINE_THRESHOLD); 775 } else { 776 wrapper = newTarget; // no need for a counting wrapper anymore 777 } 778 return (asTypeCache = wrapper); 779 } 780 781 // Customize target if counting happens for too long. 782 private int invocations = CUSTOMIZE_THRESHOLD; 783 private void maybeCustomizeTarget() { 784 int c = invocations; 785 if (c >= 0) { 786 if (c == 1) { 787 target.customize(); 788 } 789 invocations = c - 1; 790 } 791 } 792 793 boolean countDown() { 794 int c = count; 795 maybeCustomizeTarget(); 796 if (c <= 1) { 797 // Try to limit number of updates. MethodHandle.updateForm() doesn't guarantee LF update visibility. 798 if (isCounting) { 799 isCounting = false; 800 return true; 801 } else { 802 return false; 803 } 804 } else { 805 count = c - 1; 806 return false; 807 } 808 } 809 810 @Hidden 811 static void maybeStopCounting(Object o1) { 812 CountingWrapper wrapper = (CountingWrapper) o1; 813 if (wrapper.countDown()) { 814 // Reached invocation threshold. Replace counting behavior with a non-counting one. 815 LambdaForm lform = wrapper.nonCountingFormProducer.apply(wrapper.target); |