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

JDK-8251986: [lworld] implement Class::valueType and Class::referenceType in Java #152

Closed
wants to merge 11 commits into from
@@ -643,7 +643,25 @@ private boolean isReferenceProjectionType() {

private transient Class<?>[] projectionTypes;
private Class<?>[] getProjectionTypes() {
ensureProjectionTypesInited();
if (isPrimitive() || isArray() || isInterface())
return null;

Class<?>[] valRefTypes = projectionTypes;
if (valRefTypes == null) {
// C.ensureProjectionTypesInited calls initProjectionTypes that may
// call D.ensureProjectionTypesInited where D is its superclass.
// So initProjectionTypes is called without holding any lock to
// avoid potential deadlock when multiple threads attempt to
// initialize the projection types for C and E where D is
// the superclass of both C and E (which is an error case)
valRefTypes = newProjectionTypeArray();
}
synchronized (this) {
// set the projection types if not set
if (projectionTypes == null) {
projectionTypes = valRefTypes;
}
}
return projectionTypes;
}

@@ -715,27 +733,6 @@ private boolean isReferenceProjectionType() {
return null;
}

private void ensureProjectionTypesInited() {
if (isPrimitive() || isArray() || isInterface())
return;

Class<?>[] valRefTypes = projectionTypes;
if (valRefTypes == null) {
// C.ensureProjectionTypesInited calls initProjectionTypes that may
// call D.ensureProjectionTypesInited where D is its superclass.
// So initProjectionTypes is called without holding any lock to
// avoid potential deadlock when multiple threads attempt to
// initialize the projection types for C and E where D is
// the superclass of both C and E (which is an error case)
valRefTypes = newProjectionTypeArray();
}
synchronized (this) {
if (projectionTypes == null) {
projectionTypes = valRefTypes;
}
}
}

/**
* Creates a new instance of the class represented by this {@code Class}
* object. The class is instantiated as if by a {@code new}