Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8273000: Remove WeakReference-based class initialisation barrier implementation #5258

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -381,8 +381,12 @@ public LambdaForm apply(LambdaForm oldForm) {
}
private static boolean checkInitialized(MemberName member) {
Class<?> defc = member.getDeclaringClass();
UNSAFE.ensureClassInitialized(defc); // initialization barrier; blocks unless called by the initializing thread
return !UNSAFE.shouldBeInitialized(defc); // keep the barrier if the initialization is still in progress
UNSAFE.ensureClassInitialized(defc);
// Once we get here either defc was fully initialized by another thread, or
// defc was already being initialized by the current thread. In the latter case
// the barrier must remain. We can detect this simply by checking if initialization
// is still needed.
return !UNSAFE.shouldBeInitialized(defc);
}

/*non-public*/
@@ -1143,9 +1143,13 @@ public boolean shouldBeInitialized(Class<?> c) {
}

/**
* Ensures the given class has been initialized. This is often
* needed in conjunction with obtaining the static field base of a
* class.
* Ensures the given class has been initialized (see JVMS-5.5 for details).
* This is often needed in conjunction with obtaining the static field base
* of a class.
*
* The call returns when either class {@code c} is fully initialized or
* class {@code c} is being initialized and the call is performed from
* the initializing thread.
Copy link
Member

@PaulSandoz PaulSandoz Sep 1, 2021

Choose a reason for hiding this comment

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

Suggested change
* The call returns when either class {@code c} is fully initialized or
* class {@code c} is being initialized and the call is performed from
* the initializing thread.
* The call returns when either class {@code c} is fully initialized or
* class {@code c} is being initialized and the call is performed from
* the initializing thread. In the latter case a subsequent call to
* {@link #shouldBeInitialized}, from the calling thread of this call,
* will return {@code true}.

Copy link
Member

@dholmes-ora dholmes-ora Sep 2, 2021

Choose a reason for hiding this comment

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

Aren't "the calling thread of this call" and "the initializing thread" the same thread in the latter case?

Copy link
Author

@iwanowww iwanowww Sep 2, 2021

Choose a reason for hiding this comment

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

Agree. I dropped "from the calling thread of this call" part and incorporated the rest into the latest version.

*/
public void ensureClassInitialized(Class<?> c) {
if (c == null) {