6995195: Static initialization deadlock in sun.java2d.loops.Blit and GraphicsPrimitiveMgr

Reviewed-by: serb, aivanov
This commit is contained in:
Dmitry Cherepanov 2023-04-27 07:06:24 +00:00
parent 748476fd80
commit de0c05da07
10 changed files with 127 additions and 42 deletions

View file

@ -42,7 +42,6 @@ public final class GraphicsPrimitiveMgr {
private static final boolean debugTrace = false;
private static GraphicsPrimitive[] primitives;
private static GraphicsPrimitive[] generalPrimitives;
private static boolean needssort = true;
private static native void initIDs(Class<?> GP, Class<?> ST, Class<?> CT,
@ -121,24 +120,6 @@ public final class GraphicsPrimitiveMgr {
primitives = temp;
}
/**
* Registers the general loop which will be used to produce specific
* primitives by the {@link GraphicsPrimitive#makePrimitive} function.
*
* @param gen the graphics primitive to be registered as the general loop
*/
public static synchronized void registerGeneral(GraphicsPrimitive gen) {
if (generalPrimitives == null) {
generalPrimitives = new GraphicsPrimitive[] {gen};
return;
}
int len = generalPrimitives.length;
GraphicsPrimitive[] newGen = new GraphicsPrimitive[len + 1];
System.arraycopy(generalPrimitives, 0, newGen, 0, len);
newGen[len] = gen;
generalPrimitives = newGen;
}
public static synchronized GraphicsPrimitive locate(int primTypeID,
SurfaceType dsttype)
{
@ -165,7 +146,7 @@ public final class GraphicsPrimitiveMgr {
if (prim == null) {
//System.out.println("Trying general loop");
prim = locateGeneral(primTypeID);
prim = GeneralPrimitives.locate(primTypeID);
if (prim != null) {
prim = prim.makePrimitive(srctype, comptype, dsttype);
if (prim != null && GraphicsPrimitive.traceflags != 0) {
@ -218,20 +199,6 @@ public final class GraphicsPrimitiveMgr {
return null;
}
private static GraphicsPrimitive locateGeneral(int primTypeID) {
if (generalPrimitives == null) {
return null;
}
for (int i = 0; i < generalPrimitives.length; i++) {
GraphicsPrimitive prim = generalPrimitives[i];
if (prim.getPrimTypeID() == primTypeID) {
return prim;
}
}
return null;
//throw new InternalError("No general handler registered for"+signature);
}
private static GraphicsPrimitive locate(PrimitiveSpec spec) {
if (needssort) {
if (GraphicsPrimitive.traceflags != 0) {
@ -274,6 +241,46 @@ public final class GraphicsPrimitiveMgr {
}
}
/**
* A holder for general primitives to avoid circular dependencies
* between GraphicsPrimitiveMgr and Blit/etc classes.
*/
final static class GeneralPrimitives {
private static GraphicsPrimitive[] primitives;
/**
* Registers the general loop which will be used to produce specific
* primitives by the {@link GraphicsPrimitive#makePrimitive} function.
*
* @param gen the graphics primitive to be registered as the general loop
*/
static synchronized void register(GraphicsPrimitive gen) {
if (primitives == null) {
primitives = new GraphicsPrimitive[]{gen};
return;
}
int len = primitives.length;
GraphicsPrimitive[] newGen = new GraphicsPrimitive[len + 1];
System.arraycopy(primitives, 0, newGen, 0, len);
newGen[len] = gen;
primitives = newGen;
}
static synchronized GraphicsPrimitive locate(int primTypeID) {
if (primitives == null) {
return null;
}
for (int i = 0; i < primitives.length; i++) {
GraphicsPrimitive prim = primitives[i];
if (prim.getPrimTypeID() == primTypeID) {
return prim;
}
}
return null;
}
}
/**
* Test that all of the GraphicsPrimitiveProxy objects actually
* resolve to something. Throws a RuntimeException if anything