mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Make clinit optimization weaker in order to properly handle case
when clinit method reads state that was set somewhere in main method
This commit is contained in:
parent
d2a7e31eca
commit
45d31da85c
|
@ -210,20 +210,24 @@ public class ClassInitializerAnalysis implements ClassInitializerInfo {
|
||||||
public void getField(VariableReader receiver, VariableReader instance, FieldReference field,
|
public void getField(VariableReader receiver, VariableReader instance, FieldReference field,
|
||||||
ValueType fieldType) {
|
ValueType fieldType) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
analyzeInitializer(field.getClassName());
|
touchField(field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putField(VariableReader instance, FieldReference field, VariableReader value, ValueType fieldType) {
|
public void putField(VariableReader instance, FieldReference field, VariableReader value, ValueType fieldType) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
analyzeInitializer(field.getClassName());
|
touchField(field);
|
||||||
if (!methodInfo.anyFieldModified && !field.getClassName().equals(currentClass)) {
|
}
|
||||||
if (methodInfo.classesWithModifiedFields == null) {
|
}
|
||||||
methodInfo.classesWithModifiedFields = new HashSet<>();
|
|
||||||
}
|
private void touchField(FieldReference field) {
|
||||||
methodInfo.classesWithModifiedFields.add(field.getClassName());
|
analyzeInitializer(field.getClassName());
|
||||||
|
if (!methodInfo.anyFieldModified && !field.getClassName().equals(currentClass)) {
|
||||||
|
if (methodInfo.classesWithModifiedFields == null) {
|
||||||
|
methodInfo.classesWithModifiedFields = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
methodInfo.classesWithModifiedFields.add(field.getClassName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -303,6 +303,12 @@ public class VMTest {
|
||||||
assertEquals("default,A;default,B;overridden,C;", sb.toString());
|
assertEquals("default,A;default,B;overridden,C;", sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void clinitReadsState() {
|
||||||
|
initCount = 23;
|
||||||
|
assertEquals(23, ReadingStateInClinit.state);
|
||||||
|
}
|
||||||
|
|
||||||
interface WithDefaultMethod {
|
interface WithDefaultMethod {
|
||||||
default String foo() {
|
default String foo() {
|
||||||
return "default";
|
return "default";
|
||||||
|
@ -342,6 +348,10 @@ public class VMTest {
|
||||||
|
|
||||||
static int initCount;
|
static int initCount;
|
||||||
|
|
||||||
|
private static class ReadingStateInClinit {
|
||||||
|
public static final int state = initCount;
|
||||||
|
}
|
||||||
|
|
||||||
private static class AsyncClinitClass {
|
private static class AsyncClinitClass {
|
||||||
static String state = "";
|
static String state = "";
|
||||||
String instanceState = "";
|
String instanceState = "";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user