Skip to content

Commit e279970

Browse files
committed
[GR-31508] Remove redundant state in Member.
PullRequest: graal/8990
2 parents afc6206 + 0648470 commit e279970

File tree

5 files changed

+36
-39
lines changed

5 files changed

+36
-39
lines changed

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/impl/Field.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -53,14 +53,18 @@ public final class Field extends Member<Type> implements FieldRef {
5353

5454
@CompilationFinal private Symbol<ModifiedUTF8> genericSignature = null;
5555

56-
public Field(ObjectKlass holder, LinkedField linkedField, boolean hidden) {
57-
super(hidden ? null : linkedField.getType(), linkedField.getName());
56+
public Field(ObjectKlass holder, LinkedField linkedField) {
5857
this.linkedField = linkedField;
5958
this.holder = holder;
6059
}
6160

61+
@Override
62+
public Symbol<Name> getName() {
63+
return linkedField.getName();
64+
}
65+
6266
public Symbol<Type> getType() {
63-
return descriptor;
67+
return linkedField.getType();
6468
}
6569

6670
public Attribute[] getAttributes() {
@@ -80,7 +84,7 @@ public Symbol<ModifiedUTF8> getGenericSignature() {
8084
}
8185

8286
public boolean isHidden() {
83-
return getDescriptor() == null;
87+
return linkedField.isHidden();
8488
}
8589

8690
public JavaKind getKind() {
@@ -616,12 +620,12 @@ public byte getTagConstant() {
616620

617621
@Override
618622
public String getNameAsString() {
619-
return super.getName().toString();
623+
return getName().toString();
620624
}
621625

622626
@Override
623627
public String getTypeAsString() {
624-
return super.getDescriptor().toString();
628+
return getType().toString();
625629
}
626630

627631
@Override

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/impl/LinkedField.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ final class LinkedField extends StaticProperty {
3939
this.slot = slot;
4040
}
4141

42-
public static LinkedField createHidden(Symbol<Name> name, int slot) {
43-
return new LinkedField(new ParserField(ParserField.HIDDEN, name, Type.java_lang_Object, null), slot);
44-
}
45-
4642
/**
4743
* This method is required by the Static Object Model. In Espresso we should rather call
4844
* `getName()` and use Symbols.

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/impl/Member.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,21 +29,7 @@
2929

3030
public abstract class Member<T extends Descriptor> implements ModifiersProvider {
3131

32-
protected final Symbol<Name> name;
33-
protected final Symbol<T> descriptor;
34-
35-
protected Member(Symbol<T> descriptor, Symbol<Name> name) {
36-
this.name = name;
37-
this.descriptor = descriptor;
38-
}
39-
40-
public Symbol<Name> getName() {
41-
return name;
42-
}
43-
44-
public final Symbol<T> getDescriptor() {
45-
return descriptor;
46-
}
32+
public abstract Symbol<Name> getName();
4733

4834
public abstract ObjectKlass getDeclaringKlass();
4935
}

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/impl/Method.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,24 +131,32 @@ public final class Method extends Member<Signature> implements TruffleObject, Co
131131
private final Method proxy;
132132
private String genericSignature;
133133

134+
// always null unless the raw signature exposed for this method should be
135+
// different from the one in the linkedKlass
136+
private final Symbol<Signature> rawSignature;
137+
134138
// the parts of the method that can change when it's redefined
135139
// are encapsulated within the methodVersion
136140
@CompilationFinal private volatile MethodVersion methodVersion;
137141

138142
private final Assumption removedByRedefinition = Truffle.getRuntime().createAssumption();
139143

140-
public Method identity() {
141-
return proxy == null ? this : proxy;
142-
}
143-
144144
// Multiple maximally-specific interface methods. Fail on call.
145145
@CompilationFinal private boolean poisonPill = false;
146146

147147
// Whether we need to use an additional frame slot for monitor unlock on kill.
148148
@CompilationFinal private byte usesMonitors = -1;
149149

150-
// can have a different constant pool than it's declaring class
150+
public Method identity() {
151+
return proxy == null ? this : proxy;
152+
}
153+
154+
@Override
155+
public Symbol<Name> getName() {
156+
return getLinkedMethod().getName();
157+
}
151158

159+
// can have a different constant pool than it's declaring class
152160
public ConstantPool getConstantPool() {
153161
return getRuntimeConstantPool();
154162
}
@@ -171,7 +179,10 @@ public ObjectKlass getDeclaringKlass() {
171179
}
172180

173181
public Symbol<Signature> getRawSignature() {
174-
return descriptor;
182+
if (rawSignature != null) {
183+
return rawSignature;
184+
}
185+
return getLinkedMethod().getRawSignature();
175186
}
176187

177188
public Symbol<Type>[] getParsedSignature() {
@@ -182,7 +193,7 @@ public Symbol<Type>[] getParsedSignature() {
182193
private Source source;
183194

184195
Method(Method method) {
185-
super(method.getRawSignature(), method.getName());
196+
this.rawSignature = method.rawSignature;
186197
this.declaringKlass = method.declaringKlass;
187198
this.methodVersion = new MethodVersion(method.getRuntimeConstantPool(), method.getLinkedMethod(), method.getCodeAttribute());
188199

@@ -205,7 +216,7 @@ public Symbol<Type>[] getParsedSignature() {
205216
}
206217

207218
private Method(Method method, CodeAttribute split) {
208-
super(method.getRawSignature(), method.getName());
219+
this.rawSignature = method.rawSignature;
209220
this.declaringKlass = method.declaringKlass;
210221
this.methodVersion = new MethodVersion(method.getRuntimeConstantPool(), method.getLinkedMethod(), split);
211222

@@ -231,9 +242,9 @@ private Method(Method method, CodeAttribute split) {
231242
}
232243

233244
Method(ObjectKlass declaringKlass, LinkedMethod linkedMethod, Symbol<Signature> rawSignature, RuntimeConstantPool pool) {
234-
super(rawSignature, linkedMethod.getName());
235245
this.methodVersion = new MethodVersion(pool, linkedMethod, (CodeAttribute) linkedMethod.getAttribute(CodeAttribute.NAME));
236246
this.declaringKlass = declaringKlass;
247+
this.rawSignature = rawSignature;
237248

238249
try {
239250
this.parsedSignature = getSignatures().parsed(this.getRawSignature());

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/impl/ObjectKlass.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ public ObjectKlass(EspressoContext context, LinkedKlass linkedKlass, ObjectKlass
163163
System.arraycopy(skFieldTable, 0, fieldTable, 0, skFieldTable.length);
164164
localFieldTableIndex = skFieldTable.length;
165165
for (int i = 0; i < lkInstanceFields.length; i++) {
166-
Field instanceField = new Field(this, lkInstanceFields[i], lkInstanceFields[i].isHidden());
166+
Field instanceField = new Field(this, lkInstanceFields[i]);
167167
fieldTable[localFieldTableIndex + i] = instanceField;
168168
}
169169
for (int i = 0; i < lkStaticFields.length; i++) {
170-
Field staticField = new Field(this, lkStaticFields[i], false);
170+
Field staticField = new Field(this, lkStaticFields[i]);
171171
staticFieldTable[i] = staticField;
172172
}
173173

@@ -1117,7 +1117,7 @@ public void redefineClass(ChangePacket packet, List<ObjectKlass> refreshSubClass
11171117
for (LinkedField instanceField : instanceFields) {
11181118
if (instanceField.getName().equals(outerField.getName())) {
11191119
// replace with new field
1120-
fieldTable[i] = new Field(this, instanceField, false);
1120+
fieldTable[i] = new Field(this, instanceField);
11211121
}
11221122
}
11231123
}

0 commit comments

Comments
 (0)