Skip to content

Commit

Permalink
8297784: Optimize @stable field for Method.isCallerSensitive
Browse files Browse the repository at this point in the history
Reviewed-by: redestad, jvernee, alanb
  • Loading branch information
shipilev committed Dec 2, 2022
1 parent 11ba759 commit 9bbcb54
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/java.base/share/classes/java/lang/reflect/Method.java
Expand Up @@ -605,13 +605,17 @@ private Object invoke(Object obj, Object[] args, Class<?> caller)
return callerSensitive ? ma.invoke(obj, args, caller) : ma.invoke(obj, args);
}

@Stable private Boolean callerSensitive; // lazily initialize
// 0 = not initialized (@Stable contract)
// 1 = initialized, CS
// -1 = initialized, not CS
@Stable private byte callerSensitive;

private boolean isCallerSensitive() {
Boolean cs = callerSensitive;
if (cs == null) {
callerSensitive = cs = Reflection.isCallerSensitive(this);
byte cs = callerSensitive;
if (cs == 0) {
callerSensitive = cs = (byte)(Reflection.isCallerSensitive(this) ? 1 : -1);
}
return cs;
return (cs > 0);
}

/**
Expand Down

1 comment on commit 9bbcb54

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.