Skip to content

Commit 8277394

Browse files
author
attila
committed
8009758: reactivate the 8006529 test.
Reviewed-by: jlaskey, sundar
1 parent 3f11e95 commit 8277394

File tree

7 files changed

+135
-101
lines changed

7 files changed

+135
-101
lines changed

src/jdk/nashorn/internal/codegen/Attr.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
import jdk.nashorn.internal.runtime.JSType;
9595
import jdk.nashorn.internal.runtime.Property;
9696
import jdk.nashorn.internal.runtime.PropertyMap;
97-
import jdk.nashorn.internal.runtime.ScriptObject;
9897

9998
/**
10099
* This is the attribution pass of the code generator. Attr takes Lowered IR,
@@ -166,19 +165,19 @@ public Node leaveAccessNode(final AccessNode accessNode) {
166165
}
167166

168167
private void initFunctionWideVariables(final FunctionNode functionNode, final Block body) {
169-
initCompileConstant(CALLEE, body, IS_PARAM | IS_INTERNAL, FunctionNode.FUNCTION_TYPE);
168+
initCompileConstant(CALLEE, body, IS_PARAM | IS_INTERNAL);
170169
initCompileConstant(THIS, body, IS_PARAM | IS_THIS, Type.OBJECT);
171170

172171
if (functionNode.isVarArg()) {
173-
initCompileConstant(VARARGS, body, IS_PARAM | IS_INTERNAL, Type.OBJECT_ARRAY);
172+
initCompileConstant(VARARGS, body, IS_PARAM | IS_INTERNAL);
174173
if (functionNode.needsArguments()) {
175-
initCompileConstant(ARGUMENTS, body, IS_VAR | IS_INTERNAL | IS_ALWAYS_DEFINED, Type.typeFor(ScriptObject.class));
174+
initCompileConstant(ARGUMENTS, body, IS_VAR | IS_INTERNAL | IS_ALWAYS_DEFINED);
176175
addLocalDef(ARGUMENTS.symbolName());
177176
}
178177
}
179178

180179
initParameters(functionNode, body);
181-
initCompileConstant(SCOPE, body, IS_VAR | IS_INTERNAL | IS_ALWAYS_DEFINED, Type.typeFor(ScriptObject.class));
180+
initCompileConstant(SCOPE, body, IS_VAR | IS_INTERNAL | IS_ALWAYS_DEFINED);
182181
initCompileConstant(RETURN, body, IS_VAR | IS_INTERNAL | IS_ALWAYS_DEFINED, Type.OBJECT);
183182
}
184183

@@ -1424,9 +1423,16 @@ public Node leaveTernaryNode(final TernaryNode ternaryNode) {
14241423
return end(ensureSymbol(type, ternaryNode));
14251424
}
14261425

1426+
private void initCompileConstant(final CompilerConstants cc, final Block block, final int flags) {
1427+
final Class<?> type = cc.type();
1428+
// Must not call this method for constants with no explicit types; use the one with (..., Type) signature instead.
1429+
assert type != null;
1430+
initCompileConstant(cc, block, flags, Type.typeFor(type));
1431+
}
1432+
14271433
private void initCompileConstant(final CompilerConstants cc, final Block block, final int flags, final Type type) {
14281434
final Symbol symbol = defineSymbol(block, cc.symbolName(), flags);
1429-
newType(symbol, type);
1435+
symbol.setTypeOverride(type);
14301436
symbol.setNeedsSlot(true);
14311437
}
14321438

src/jdk/nashorn/internal/codegen/CompilerConstants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ public enum CompilerConstants {
100100
CALLEE(":callee", ScriptFunction.class),
101101

102102
/** the varargs variable when necessary */
103-
VARARGS(":varargs"),
103+
VARARGS(":varargs", Object[].class),
104104

105105
/** the arguments vector when necessary and the slot */
106-
ARGUMENTS("arguments", Object.class, 2),
106+
ARGUMENTS("arguments", ScriptObject.class, 2),
107107

108108
/** prefix for iterators for for (x in ...) */
109109
ITERATOR_PREFIX(":i", Iterator.class),

src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,13 @@ private static MethodEmitter newInitScopeMethod(final ClassEmitter classEmitter)
435435
* @return Open method emitter.
436436
*/
437437
private static MethodEmitter newInitScopeWithArgumentsMethod(final ClassEmitter classEmitter) {
438-
final MethodEmitter init = classEmitter.init(PropertyMap.class, ScriptObject.class, Object.class);
438+
final MethodEmitter init = classEmitter.init(PropertyMap.class, ScriptObject.class, ScriptObject.class);
439439
init.begin();
440440
init.load(Type.OBJECT, JAVA_THIS.slot());
441441
init.load(Type.OBJECT, INIT_MAP.slot());
442442
init.load(Type.OBJECT, INIT_SCOPE.slot());
443443
init.load(Type.OBJECT, INIT_ARGUMENTS.slot());
444-
init.invoke(constructorNoLookup(FunctionScope.class, PropertyMap.class, ScriptObject.class, Object.class));
444+
init.invoke(constructorNoLookup(FunctionScope.class, PropertyMap.class, ScriptObject.class, ScriptObject.class));
445445

446446
return init;
447447
}

src/jdk/nashorn/internal/codegen/types/Type.java

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@
4747
import static jdk.internal.org.objectweb.asm.Opcodes.T_LONG;
4848

4949
import java.lang.invoke.MethodHandle;
50-
import java.util.Collections;
51-
import java.util.HashMap;
52-
import java.util.Map;
50+
import java.util.concurrent.ConcurrentHashMap;
51+
import java.util.concurrent.ConcurrentMap;
5352
import jdk.internal.org.objectweb.asm.MethodVisitor;
5453
import jdk.nashorn.internal.codegen.CompilerConstants.Call;
5554

@@ -548,19 +547,19 @@ public String toString() {
548547
* @return the Type representing this class
549548
*/
550549
public static Type typeFor(final Class<?> clazz) {
551-
Type type = cache.get(clazz);
552-
553-
if (type == null) {
554-
assert !clazz.isPrimitive() || clazz == void.class;
555-
if (clazz.isArray()) {
556-
type = new ArrayType(clazz);
557-
} else {
558-
type = new ObjectType(clazz);
559-
}
560-
cache.put(clazz, type);
550+
final Type type = cache.get(clazz);
551+
if(type != null) {
552+
return type;
553+
}
554+
assert !clazz.isPrimitive() || clazz == void.class;
555+
final Type newType;
556+
if (clazz.isArray()) {
557+
newType = new ArrayType(clazz);
558+
} else {
559+
newType = new ObjectType(clazz);
561560
}
562-
563-
return type;
561+
final Type existingType = cache.putIfAbsent(clazz, newType);
562+
return existingType == null ? newType : existingType;
564563
}
565564

566565
@Override
@@ -663,35 +662,38 @@ private static void swap(final MethodVisitor method, final Type above, final Typ
663662
}
664663
}
665664

665+
/** Mappings between java classes and their Type singletons */
666+
private static final ConcurrentMap<Class<?>, Type> cache = new ConcurrentHashMap<>();
667+
666668
/**
667669
* This is the boolean singleton, used for all boolean types
668670
*/
669-
public static final Type BOOLEAN = new BooleanType();
671+
public static final Type BOOLEAN = putInCache(new BooleanType());
670672

671673
/**
672674
* This is an integer type, i.e INT, INT32.
673675
*/
674-
public static final Type INT = new IntType();
676+
public static final Type INT = putInCache(new IntType());
675677

676678
/**
677679
* This is the number singleton, used for all number types
678680
*/
679-
public static final Type NUMBER = new NumberType();
681+
public static final Type NUMBER = putInCache(new NumberType());
680682

681683
/**
682684
* This is the long singleton, used for all long types
683685
*/
684-
public static final Type LONG = new LongType();
686+
public static final Type LONG = putInCache(new LongType());
685687

686688
/**
687689
* A string singleton
688690
*/
689-
public static final Type STRING = new ObjectType(String.class);
691+
public static final Type STRING = putInCache(new ObjectType(String.class));
690692

691693
/**
692694
* This is the object singleton, used for all object types
693695
*/
694-
public static final Type OBJECT = new ObjectType();
696+
public static final Type OBJECT = putInCache(new ObjectType());
695697

696698
/**
697699
* This is the singleton for integer arrays
@@ -775,13 +777,13 @@ public Type getElementType() {
775777
};
776778

777779
/** Singleton for method handle arrays used for properties etc. */
778-
public static final ArrayType METHODHANDLE_ARRAY = new ArrayType(MethodHandle[].class);
780+
public static final ArrayType METHODHANDLE_ARRAY = putInCache(new ArrayType(MethodHandle[].class));
779781

780782
/** This is the singleton for string arrays */
781-
public static final ArrayType STRING_ARRAY = new ArrayType(String[].class);
783+
public static final ArrayType STRING_ARRAY = putInCache(new ArrayType(String[].class));
782784

783785
/** This is the singleton for object arrays */
784-
public static final ArrayType OBJECT_ARRAY = new ArrayType(Object[].class);
786+
public static final ArrayType OBJECT_ARRAY = putInCache(new ArrayType(Object[].class));
785787

786788
/** This type, always an object type, just a toString override */
787789
public static final Type THIS = new ObjectType() {
@@ -855,18 +857,8 @@ public Type add(final MethodVisitor method) {
855857
}
856858
};
857859

858-
/** Mappings between java classes and their Type singletons */
859-
private static final Map<Class<?>, Type> cache = Collections.synchronizedMap(new HashMap<Class<?>, Type>());
860-
861-
//TODO may need to be cleared, as all types are retained throughout code generation
862-
static {
863-
cache.put(BOOLEAN.getTypeClass(), BOOLEAN);
864-
cache.put(INT.getTypeClass(), INT);
865-
cache.put(LONG.getTypeClass(), LONG);
866-
cache.put(NUMBER.getTypeClass(), NUMBER);
867-
cache.put(STRING.getTypeClass(), STRING);
868-
cache.put(OBJECT.getTypeClass(), OBJECT);
869-
cache.put(OBJECT_ARRAY.getTypeClass(), OBJECT_ARRAY);
860+
private static <T extends Type> T putInCache(T type) {
861+
cache.put(type.getTypeClass(), type);
862+
return type;
870863
}
871-
872864
}

src/jdk/nashorn/internal/runtime/AccessorProperty.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,10 @@ public AccessorProperty(final String key, final int flags, final Class<?> struct
248248
primitiveSetter = null;
249249

250250
if (isParameter() && hasArguments()) {
251-
final MethodHandle arguments = MH.getter(lookup, structure, "arguments", Object.class);
252-
final MethodHandle argumentsSO = MH.asType(arguments, arguments.type().changeReturnType(ScriptObject.class));
251+
final MethodHandle arguments = MH.getter(lookup, structure, "arguments", ScriptObject.class);
253252

254-
objectGetter = MH.asType(MH.insertArguments(MH.filterArguments(ScriptObject.GET_ARGUMENT.methodHandle(), 0, argumentsSO), 1, slot), Lookup.GET_OBJECT_TYPE);
255-
objectSetter = MH.asType(MH.insertArguments(MH.filterArguments(ScriptObject.SET_ARGUMENT.methodHandle(), 0, argumentsSO), 1, slot), Lookup.SET_OBJECT_TYPE);
253+
objectGetter = MH.asType(MH.insertArguments(MH.filterArguments(ScriptObject.GET_ARGUMENT.methodHandle(), 0, arguments), 1, slot), Lookup.GET_OBJECT_TYPE);
254+
objectSetter = MH.asType(MH.insertArguments(MH.filterArguments(ScriptObject.SET_ARGUMENT.methodHandle(), 0, arguments), 1, slot), Lookup.SET_OBJECT_TYPE);
256255
} else {
257256
final GettersSetters gs = GETTERS_SETTERS.get(structure);
258257
objectGetter = gs.getters[slot];

src/jdk/nashorn/internal/runtime/FunctionScope.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
public class FunctionScope extends ScriptObject implements Scope {
4242

4343
/** Area to store scope arguments. (public for access from scripts.) */
44-
public final Object arguments;
44+
public final ScriptObject arguments;
4545

4646
/** Flag to indicate that a split method issued a return statement */
4747
private int splitState = -1;
@@ -53,7 +53,7 @@ public class FunctionScope extends ScriptObject implements Scope {
5353
* @param callerScope caller scope
5454
* @param arguments arguments
5555
*/
56-
public FunctionScope(final PropertyMap map, final ScriptObject callerScope, final Object arguments) {
56+
public FunctionScope(final PropertyMap map, final ScriptObject callerScope, final ScriptObject arguments) {
5757
super(callerScope, map);
5858
this.arguments = arguments;
5959
setIsScope();

0 commit comments

Comments
 (0)