Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
mcimadamore committed Oct 25, 2023
1 parent d713427 commit 0e44f14
Show file tree
Hide file tree
Showing 16 changed files with 283 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ public enum Feature {
UNNAMED_CLASSES(JDK21, Fragments.FeatureUnnamedClasses, DiagKind.PLURAL),
WARN_ON_ILLEGAL_UTF8(MIN, JDK21),
UNNAMED_VARIABLES(JDK21, Fragments.FeatureUnnamedVariables, DiagKind.PLURAL),
LAZY_STATICS(JDK22),
;

enum DiagKind {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1783,20 +1783,10 @@ public Object getConstValue() {
} catch (Exception ex) {
throw new AssertionError(ex);
}
} else if (data instanceof DynamicVarSymbol) {
return null; // ignore
}
return data;
}

public DynamicVarSymbol lazyConstValue() {
if (data instanceof DynamicVarSymbol dsym) {
return dsym;
} else {
return null;
}
}

public void setData(Object data) {
Assert.check(!(data instanceof Env<?>), this);
this.data = data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public static Symtab instance(Context context) {
public final Type processorType;
public final Type linkageType;

// for lazy statics
// for static locals
public final Type constantBootstraps;

/** The symbol representing the length field of an array.
Expand Down Expand Up @@ -648,7 +648,7 @@ public <R, P> R accept(ElementVisitor<R, P> v, P p) {
processorType = enterClass("java.lang.StringTemplate$Processor");
linkageType = enterClass("java.lang.StringTemplate$Processor$Linkage");

// for lazy statics
// for static locals
constantBootstraps = enterClass("java.lang.invoke.ConstantBootstraps");

// Enter a synthetic class that is used to mark internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1213,10 +1213,8 @@ long checkFlags(DiagnosticPosition pos, long flags, Symbol sym, JCTree tree) {
mask = ReceiverParamFlags;
else if (sym.owner.kind != TYP)
mask = LocalVarFlags;
else if ((sym.owner.flags_field & INTERFACE) != 0) {
implicit = InterfaceVarFlags;
mask = InterfaceVarFlags;
}
else if ((sym.owner.flags_field & INTERFACE) != 0)
mask = implicit = InterfaceVarFlags;
else
mask = VarFlags;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ public enum CompileState {
TRANSTYPES(6),
TRANSLITERALS(7),
TRANSPATTERNS(8),
UNLAMBDA(9),
LOWER(10),
GENERATE(11);
TRANSCONSTANTS(9),
UNLAMBDA(10),
LOWER(11),
GENERATE(12);

CompileState(int value) {
this.value = value;
Expand Down
43 changes: 2 additions & 41 deletions src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java
Original file line number Diff line number Diff line change
Expand Up @@ -1124,10 +1124,6 @@ MethodSymbol accessSymbol(Symbol sym, JCTree tree, JCTree enclOp,
return accessor;
}

Name lazyStaticInitName(Symbol sym) {
return sym.name.append('$', names.fromString("init"));
}

/** The qualifier to be used for accessing a symbol in an outer class.
* This is either C.sym or C.this.sym, depending on whether or not
* sym is static.
Expand Down Expand Up @@ -1259,6 +1255,7 @@ JCExpression access(Symbol sym, JCExpression tree, JCExpression enclOp, boolean
break;
case MTH: case VAR:
if (sym.owner.kind == TYP) {

// Access methods are required for
// - private members,
// - protected members in a superclass of an
Expand Down Expand Up @@ -3675,47 +3672,11 @@ public void visitVarDef(JCVariableDecl tree) {
names.empty, null,
currentClass);
}
// handle static locals
if (tree.sym.isStatic() && tree.sym.owner.kind == MTH) {
splitInit(tree);
} else {
if (tree.init != null) tree.init = translate(tree.init, tree.type);
}
if (tree.init != null) tree.init = translate(tree.init, tree.type);
result = tree;
currentMethodSym = oldMethodSym;
}

private MethodSymbol splitInit(JCVariableDecl tree) {
Assert.checkNonNull(tree.init);
// create synthetic init symbol
MethodSymbol initSym = new MethodSymbol(
STATIC | SYNTHETIC | PRIVATE,
tree.name.append('$', names.fromString("init")),
new MethodType(List.nil(), tree.type, List.nil(), syms.methodClass),
currentClass);
enterSynthetic(tree.pos(), initSym, currentClass.members());
// create synthetic init tree
JCExpression initExpr = translate(tree.init, tree.type);
JCMethodDecl initDef = make.MethodDef(initSym, make.Block(0, List.of(make.Return(initExpr))));
JCClassDecl currentDecl = classDef(currentClass);
currentDecl.defs = currentDecl.defs.prepend(initDef);
// drop original init
tree.init = null;
List<Type> lazyInit_staticArgTypes = List.of(syms.methodHandleLookupType,
syms.stringType,
syms.classType,
syms.methodHandleType);

MethodSymbol bsm = rs.resolveInternalMethod(tree, attrEnv, syms.constantBootstraps,
names.invoke, lazyInit_staticArgTypes, List.nil());

// set a constant value that points to a dynamic symbol, so that Gen can emit the correct ldc
tree.sym.setData(new DynamicVarSymbol(tree.name, currentClass, bsm.asHandle(), tree.type,
new LoadableConstant[] { initSym.asHandle() }));

return initSym;
}

public void visitBlock(JCBlock tree) {
MethodSymbol oldMethodSym = currentMethodSym;
if (currentMethodSym == null) {
Expand Down
Loading

0 comments on commit 0e44f14

Please sign in to comment.