JDK-8145579 : SimpleThresholdPolicy assumes non-trivial methods to be trivial
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 9,10
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-12-16
  • Updated: 2019-09-13
  • Resolved: 2017-12-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10 JDK 11
10 b36Fixed 11Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
The relevant code in SimpleThresholdPolicy was apparently introduced by JDK-8056071. It now consults MDO to see if method is trivial. However, there are cases when that guess is wrong, notably when we are dealing with intrinsics or simple calls inside the method.

bool SimpleThresholdPolicy::is_trivial(Method* method) {
  ...
  MethodData* mdo = method->method_data();
  if (mdo != NULL && !mdo->would_profile() &&
      (method->code_size() < 5  || (mdo->num_blocks() < 4))) {
      return true;
    }
  return false;
}

See e.g. the benchmark against Unsafe.putOrdered:
 http://cr.openjdk.java.net/~shade/8145579/BadMDOPolicy.java
 http://cr.openjdk.java.net/~shade/8145579/benchmarks.jar

It works significantly worse with TieredCompilation enabled, because it gets to compile with C1 only.

Update: Perhaps, even more alarming is that Object::<init> is accepted as trivial, which makes tiered mode slower than non-tiered mode, if Object::<init> had not inlined into a hotpath:
  http://cr.openjdk.java.net/~shade/8145579/ObjectInit.java
Comments
[~redestad] This seems to be the expected behavior, at least until Klass::set_has_finalizer() is called for the first time. Are you seeing Klass::set_has_finalizer() called during execution of Hello?
10-05-2018

It seems the fix pushed here didn't fix the issue with Object::<init> being compiled to level 1 rather than 4: $ ~/jdks/10+36/bin/java -XX:+PrintCompilation Hello | grep "Object::<init" 136 2 3 java.lang.Object::<init> (1 bytes) 165 35 1 java.lang.Object::<init> (1 bytes) 165 2 3 java.lang.Object::<init> (1 bytes) made not entrant 231 35 1 java.lang.Object::<init> (1 bytes) made not entrant 261 128 1 java.lang.Object::<init> (1 bytes)
27-04-2018

http://cr.openjdk.java.net/~dlong/8145579/webrev/ A quick fix that addresses issues with intrinsics and Object::<init>, but not the broader question of the future of the is_trivial heuristic.
04-12-2017

Hi [~shade], do you have a new version of the BadMDOPolicy benchmark that uses jdk.internal.misc.Unsafe?
02-12-2017

I'm converting this to a bug because it's a regression. ILW = Performance regression due to TieredCompilation, with trivial methods, disable TieredCompilation = MMM = P3
27-11-2017

JDK-8076988 contains more examples of when the is_trivial heuristic fails. These problems should be addresses with this enhancement as well.
30-01-2017