Skip to content

Commit fd972e7

Browse files
author
Christian Wimmer
committed
[GR-41995] [GR-42103] [GR-42600] Various fixes.
PullRequest: graal/13249
2 parents 9b5f354 + a4baaa9 commit fd972e7

File tree

7 files changed

+148
-159
lines changed

7 files changed

+148
-159
lines changed

compiler/src/org.graalvm.compiler.java/src/org/graalvm/compiler/java/BciBlockMapping.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -737,30 +737,14 @@ public String toString() {
737737
private int newDuplicateBlocks;
738738
private int duplicateBlocks;
739739

740-
/**
741-
* Amount by which {@link Options#MaxDuplicationFactor} is multiplied.
742-
*/
743-
private final int maxDuplicationBoost;
744-
745740
/**
746741
* Creates a new BlockMap instance from {@code code}.
747742
*/
748743
protected BciBlockMapping(Bytecode code, DebugContext debug) {
749-
this(code, debug, 1);
750-
}
751-
752-
/**
753-
* Creates a new BlockMap instance from {@code code}.
754-
*
755-
* @param maxDuplicationBoost amount by which to multiply {@link Options#MaxDuplicationFactor}
756-
*/
757-
protected BciBlockMapping(Bytecode code, DebugContext debug, int maxDuplicationBoost) {
758744
this.code = code;
759745
this.debug = debug;
760746
this.exceptionHandlers = code.getExceptionHandlers().length != 0 ? code.getExceptionHandlers() : null;
761747
this.blockMap = new BciBlock[code.getCodeSize()];
762-
assert maxDuplicationBoost >= 1 : maxDuplicationBoost;
763-
this.maxDuplicationBoost = maxDuplicationBoost;
764748
}
765749

766750
public BciBlock[] getBlocks() {
@@ -1749,7 +1733,7 @@ private void computeBlockOrder(BciBlock initialBlock) {
17491733
OptionValues options = debug.getOptions();
17501734
double factor = MaxDuplicationFactor.getValue(options);
17511735
duplicateBlocks += newDuplicateBlocks;
1752-
if (duplicateBlocks > postJsrBlockCount * factor * maxDuplicationBoost) {
1736+
if (duplicateBlocks > postJsrBlockCount * factor) {
17531737
throw new PermanentBailoutException("Non-reducible loop requires too much duplication. " +
17541738
"Setting " + MaxDuplicationFactor.getName() + " to a value higher than " + factor + " may resolve this.");
17551739
}
@@ -1792,11 +1776,7 @@ private boolean checkBlocks(int start, BciBlock inserting) {
17921776
}
17931777

17941778
public static BciBlockMapping create(BytecodeStream stream, Bytecode code, OptionValues options, DebugContext debug, boolean hasAsyncExceptions) {
1795-
return create(stream, code, options, debug, hasAsyncExceptions, 1);
1796-
}
1797-
1798-
public static BciBlockMapping create(BytecodeStream stream, Bytecode code, OptionValues options, DebugContext debug, boolean hasAsyncExceptions, int maxDuplicationBoost) {
1799-
BciBlockMapping map = new BciBlockMapping(code, debug, maxDuplicationBoost);
1779+
BciBlockMapping map = new BciBlockMapping(code, debug);
18001780
buildMap(stream, code, options, debug, map, hasAsyncExceptions);
18011781
return map;
18021782
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/PointsToAnalysis.java

Lines changed: 94 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -299,84 +299,81 @@ public AnalysisMethod addRootMethod(Executable method, boolean invokeSpecial) {
299299
@SuppressWarnings("try")
300300
public AnalysisMethod addRootMethod(AnalysisMethod aMethod, boolean invokeSpecial) {
301301
assert !universe.sealed() : "Cannot register root methods after analysis universe is sealed.";
302-
try (Indent indent = debug.logAndIndent("add root method %s", aMethod.getName())) {
302+
AnalysisType declaringClass = aMethod.getDeclaringClass();
303+
boolean isStatic = aMethod.isStatic();
304+
WrappedSignature signature = aMethod.getSignature();
305+
int paramCount = signature.getParameterCount(!isStatic);
306+
PointsToAnalysisMethod pointsToMethod = assertPointsToAnalysisMethod(aMethod);
303307

304-
AnalysisType declaringClass = aMethod.getDeclaringClass();
305-
boolean isStatic = aMethod.isStatic();
306-
WrappedSignature signature = aMethod.getSignature();
307-
int paramCount = signature.getParameterCount(!isStatic);
308-
PointsToAnalysisMethod pointsToMethod = assertPointsToAnalysisMethod(aMethod);
309-
310-
if (isStatic) {
311-
/*
312-
* For static methods trigger analysis in the empty context. This will trigger
313-
* parsing and return the method flows graph. Then the method parameter type flows
314-
* are initialized with the corresponding parameter declared type.
315-
*/
316-
postTask(() -> {
317-
pointsToMethod.registerAsDirectRootMethod();
318-
pointsToMethod.registerAsImplementationInvoked(null);
319-
MethodFlowsGraph methodFlowsGraph = analysisPolicy.staticRootMethodGraph(this, pointsToMethod);
320-
for (int idx = 0; idx < paramCount; idx++) {
321-
AnalysisType declaredParamType = (AnalysisType) signature.getParameterType(idx, declaringClass);
322-
FormalParamTypeFlow parameter = methodFlowsGraph.getParameter(idx);
323-
if (declaredParamType.getJavaKind() == JavaKind.Object && parameter != null) {
324-
TypeFlow<?> initialParameterFlow = declaredParamType.getTypeFlow(this, true);
325-
initialParameterFlow.addUse(this, parameter);
326-
}
308+
if (isStatic) {
309+
/*
310+
* For static methods trigger analysis in the empty context. This will trigger parsing
311+
* and return the method flows graph. Then the method parameter type flows are
312+
* initialized with the corresponding parameter declared type.
313+
*/
314+
postTask(() -> {
315+
pointsToMethod.registerAsDirectRootMethod();
316+
pointsToMethod.registerAsImplementationInvoked(null);
317+
MethodFlowsGraph methodFlowsGraph = analysisPolicy.staticRootMethodGraph(this, pointsToMethod);
318+
for (int idx = 0; idx < paramCount; idx++) {
319+
AnalysisType declaredParamType = (AnalysisType) signature.getParameterType(idx, declaringClass);
320+
FormalParamTypeFlow parameter = methodFlowsGraph.getParameter(idx);
321+
if (declaredParamType.getJavaKind() == JavaKind.Object && parameter != null) {
322+
TypeFlow<?> initialParameterFlow = declaredParamType.getTypeFlow(this, true);
323+
initialParameterFlow.addUse(this, parameter);
327324
}
328-
});
329-
} else {
330-
if (invokeSpecial && pointsToMethod.isAbstract()) {
331-
throw AnalysisError.userError("Abstract methods cannot be registered as special invoke entry point.");
332325
}
326+
});
327+
} else {
328+
if (invokeSpecial && pointsToMethod.isAbstract()) {
329+
throw AnalysisError.userError("Abstract methods cannot be registered as special invoke entry point.");
330+
}
331+
/*
332+
* For special invoked methods trigger method resolution by using the
333+
* context-insensitive special invoke type flow. This will resolve the method in its
334+
* declaring class when the declaring class is instantiated.
335+
*
336+
* For virtual methods trigger method resolution by using the context-insensitive
337+
* virtual invoke type flow. Since the virtual invoke observes the receiver flow state
338+
* it will get notified for any future reachable subtypes and will resolve the method in
339+
* each subtype.
340+
*
341+
* In both cases the context-insensitive invoke parameters are initialized with the
342+
* corresponding declared type state. When a callee is resolved the method is parsed and
343+
* the actual parameter type state is propagated to the formal parameters. Then the
344+
* callee is linked and registered as implementation-invoked.
345+
*/
346+
postTask(() -> {
347+
if (invokeSpecial) {
348+
pointsToMethod.registerAsDirectRootMethod();
349+
} else {
350+
pointsToMethod.registerAsVirtualRootMethod();
351+
}
352+
InvokeTypeFlow invoke = pointsToMethod.initAndGetContextInsensitiveInvoke(PointsToAnalysis.this, null, invokeSpecial);
333353
/*
334-
* For special invoked methods trigger method resolution by using the
335-
* context-insensitive special invoke type flow. This will resolve the method in its
336-
* declaring class when the declaring class is instantiated.
337-
*
338-
* For virtual methods trigger method resolution by using the context-insensitive
339-
* virtual invoke type flow. Since the virtual invoke observes the receiver flow
340-
* state it will get notified for any future reachable subtypes and will resolve the
341-
* method in each subtype.
354+
* Initialize the type flow of the invoke's actual parameters with the corresponding
355+
* parameter declared type. Thus, when the invoke links callees it will propagate
356+
* the parameter types too.
342357
*
343-
* In both cases the context-insensitive invoke parameters are initialized with the
344-
* corresponding declared type state. When a callee is resolved the method is parsed
345-
* and the actual parameter type state is propagated to the formal parameters. Then
346-
* the callee is linked and registered as implementation-invoked.
358+
* The parameter iteration skips the primitive parameters, as these are not modeled.
359+
* The type flow of the receiver is set to the receiver type already when the invoke
360+
* is created.
347361
*/
348-
postTask(() -> {
349-
if (invokeSpecial) {
350-
pointsToMethod.registerAsDirectRootMethod();
351-
} else {
352-
pointsToMethod.registerAsVirtualRootMethod();
353-
}
354-
InvokeTypeFlow invoke = pointsToMethod.initAndGetContextInsensitiveInvoke(PointsToAnalysis.this, null, invokeSpecial);
362+
for (int idx = 1; idx < paramCount; idx++) {
355363
/*
356-
* Initialize the type flow of the invoke's actual parameters with the
357-
* corresponding parameter declared type. Thus, when the invoke links callees it
358-
* will propagate the parameter types too.
359-
*
360-
* The parameter iteration skips the primitive parameters, as these are not
361-
* modeled. The type flow of the receiver is set to the receiver type already
362-
* when the invoke is created.
364+
* Note: the Signature doesn't count the receiver of a virtual invoke as a
365+
* parameter whereas the MethodTypeFlow does, hence when accessing the parameter
366+
* type below we use idx-1 but when accessing the actual parameter flow we
367+
* simply use idx.
363368
*/
364-
for (int idx = 1; idx < paramCount; idx++) {
365-
/*
366-
* Note: the Signature doesn't count the receiver of a virtual invoke as a
367-
* parameter whereas the MethodTypeFlow does, hence when accessing the
368-
* parameter type below we use idx-1 but when accessing the actual parameter
369-
* flow we simply use idx.
370-
*/
371-
AnalysisType declaredParamType = (AnalysisType) signature.getParameterType(idx - 1, declaringClass);
372-
TypeFlow<?> actualParameterFlow = invoke.getActualParameter(idx);
373-
if (declaredParamType.getJavaKind() == JavaKind.Object && actualParameterFlow != null) {
374-
TypeFlow<?> initialParameterFlow = declaredParamType.getTypeFlow(this, true);
375-
initialParameterFlow.addUse(this, actualParameterFlow);
376-
}
369+
AnalysisType declaredParamType = (AnalysisType) signature.getParameterType(idx - 1, declaringClass);
370+
TypeFlow<?> actualParameterFlow = invoke.getActualParameter(idx);
371+
if (declaredParamType.getJavaKind() == JavaKind.Object && actualParameterFlow != null) {
372+
TypeFlow<?> initialParameterFlow = declaredParamType.getTypeFlow(this, true);
373+
initialParameterFlow.addUse(this, actualParameterFlow);
377374
}
378-
});
379-
}
375+
}
376+
});
380377
}
381378
return aMethod;
382379

@@ -397,24 +394,22 @@ public AnalysisType addRootClass(Class<?> clazz, boolean addFields, boolean addA
397394
@SuppressWarnings({"try"})
398395
@Override
399396
public AnalysisType addRootClass(AnalysisType type, boolean addFields, boolean addArrayClass) {
400-
try (Indent indent = debug.logAndIndent("add root class %s", type.getName())) {
401-
for (AnalysisField field : type.getInstanceFields(false)) {
402-
if (addFields) {
403-
field.registerAsAccessed();
404-
}
405-
/*
406-
* For system classes any instantiated (sub)type of the declared field type can be
407-
* written to the field flow.
408-
*/
409-
TypeFlow<?> fieldDeclaredTypeFlow = field.getType().getTypeFlow(this, true);
410-
fieldDeclaredTypeFlow.addUse(this, type.getContextInsensitiveAnalysisObject().getInstanceFieldFlow(this, field, true));
411-
}
412-
if (type.getSuperclass() != null) {
413-
addRootClass(type.getSuperclass(), addFields, addArrayClass);
414-
}
415-
if (addArrayClass) {
416-
addRootClass(type.getArrayClass(), false, false);
397+
for (AnalysisField field : type.getInstanceFields(false)) {
398+
if (addFields) {
399+
field.registerAsAccessed();
417400
}
401+
/*
402+
* For system classes any instantiated (sub)type of the declared field type can be
403+
* written to the field flow.
404+
*/
405+
TypeFlow<?> fieldDeclaredTypeFlow = field.getType().getTypeFlow(this, true);
406+
fieldDeclaredTypeFlow.addUse(this, type.getContextInsensitiveAnalysisObject().getInstanceFieldFlow(this, field, true));
407+
}
408+
if (type.getSuperclass() != null) {
409+
addRootClass(type.getSuperclass(), addFields, addArrayClass);
410+
}
411+
if (addArrayClass) {
412+
addRootClass(type.getArrayClass(), false, false);
418413
}
419414
return type;
420415
}
@@ -425,15 +420,13 @@ public AnalysisType addRootField(Class<?> clazz, String fieldName) {
425420
AnalysisType type = addRootClass(clazz, false, false);
426421
for (AnalysisField field : type.getInstanceFields(true)) {
427422
if (field.getName().equals(fieldName)) {
428-
try (Indent indent = debug.logAndIndent("add root field %s in class %s", fieldName, clazz.getName())) {
429-
field.registerAsAccessed();
430-
/*
431-
* For system classes any instantiated (sub)type of the declared field type can
432-
* be written to the field flow.
433-
*/
434-
TypeFlow<?> fieldDeclaredTypeFlow = field.getType().getTypeFlow(this, true);
435-
fieldDeclaredTypeFlow.addUse(this, type.getContextInsensitiveAnalysisObject().getInstanceFieldFlow(this, field, true));
436-
}
423+
field.registerAsAccessed();
424+
/*
425+
* For system classes any instantiated (sub)type of the declared field type can be
426+
* written to the field flow.
427+
*/
428+
TypeFlow<?> fieldDeclaredTypeFlow = field.getType().getTypeFlow(this, true);
429+
fieldDeclaredTypeFlow.addUse(this, type.getContextInsensitiveAnalysisObject().getInstanceFieldFlow(this, field, true));
437430
return field.getType();
438431
}
439432
}
@@ -445,14 +438,12 @@ public AnalysisType addRootStaticField(Class<?> clazz, String fieldName) {
445438
addRootClass(clazz, false, false);
446439
Field reflectField;
447440
try {
448-
try (Indent indent = debug.logAndIndent("add system static field %s in class %s", fieldName, clazz.getName())) {
449-
reflectField = clazz.getField(fieldName);
450-
AnalysisField field = metaAccess.lookupJavaField(reflectField);
451-
field.registerAsAccessed();
452-
TypeFlow<?> fieldFlow = field.getType().getTypeFlow(this, true);
453-
fieldFlow.addUse(this, field.getStaticFieldFlow());
454-
return field.getType();
455-
}
441+
reflectField = clazz.getField(fieldName);
442+
AnalysisField field = metaAccess.lookupJavaField(reflectField);
443+
field.registerAsAccessed();
444+
TypeFlow<?> fieldFlow = field.getType().getTypeFlow(this, true);
445+
fieldFlow.addUse(this, field.getStaticFieldFlow());
446+
return field.getType();
456447
} catch (NoSuchFieldException e) {
457448
throw shouldNotReachHere("field not found: " + fieldName);
458449
}

substratevm/src/com.oracle.graal.reachability/src/com/oracle/graal/reachability/ReachabilityAnalysisEngine.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.util.Set;
3333
import java.util.concurrent.ForkJoinPool;
3434

35-
import org.graalvm.compiler.debug.Indent;
3635
import org.graalvm.compiler.nodes.StructuredGraph;
3736
import org.graalvm.compiler.options.OptionValues;
3837

@@ -108,21 +107,19 @@ public AnalysisMethod addRootMethod(Executable method, boolean invokeSpecial) {
108107
@SuppressWarnings("try")
109108
@Override
110109
public AnalysisType addRootClass(AnalysisType type, boolean addFields, boolean addArrayClass) {
111-
try (Indent indent = debug.logAndIndent("add root class %s", type.getName())) {
112-
for (AnalysisField field : type.getInstanceFields(false)) {
113-
if (addFields) {
114-
field.registerAsAccessed();
115-
}
110+
for (AnalysisField field : type.getInstanceFields(false)) {
111+
if (addFields) {
112+
field.registerAsAccessed();
116113
}
114+
}
117115

118-
markTypeAsReachable(type);
116+
markTypeAsReachable(type);
119117

120-
if (type.getSuperclass() != null) {
121-
addRootClass(type.getSuperclass(), addFields, addArrayClass);
122-
}
123-
if (addArrayClass) {
124-
addRootClass(type.getArrayClass(), false, false);
125-
}
118+
if (type.getSuperclass() != null) {
119+
addRootClass(type.getSuperclass(), addFields, addArrayClass);
120+
}
121+
if (addArrayClass) {
122+
addRootClass(type.getArrayClass(), false, false);
126123
}
127124
return type;
128125
}
@@ -133,9 +130,7 @@ public AnalysisType addRootField(Class<?> clazz, String fieldName) {
133130
AnalysisType type = addRootClass(clazz, false, false);
134131
for (AnalysisField field : type.getInstanceFields(true)) {
135132
if (field.getName().equals(fieldName)) {
136-
try (Indent indent = debug.logAndIndent("add root field %s in class %s", fieldName, clazz.getName())) {
137-
field.registerAsAccessed();
138-
}
133+
field.registerAsAccessed();
139134
return field.getType();
140135
}
141136
}

0 commit comments

Comments
 (0)