Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Addressed various review comments:

1) Added comments describing accessedContainer and valueClassUsedInCode
fields of ClassConfiguration;
2) Replaced line comments with block comments;
3) Replaced a call to ClassWriter.visitNestHost with a call to
ClassWriter.visitNestMember.

Signed-off-by:  Henry Zongaro <zongaro@ca.ibm.com>
  • Loading branch information
hzongaro committed Nov 9, 2020
1 parent 981320d commit fbba191
Show file tree
Hide file tree
Showing 2 changed files with 196 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ private static class ClassConfiguration {
private String nestHost;
private boolean isVerifiable;
private boolean isReference;

/**
* @see setAccessedContainer
*/
private ClassConfiguration accessedContainer;

/**
* @see setValueClassUsedInCode
*/
private ClassConfiguration valueClassUsedInCode;

public ClassConfiguration(String name) {
Expand Down Expand Up @@ -97,18 +105,51 @@ public boolean isVerifiable() {
return this.isVerifiable;
}

/**
* This method specifies a reference class - whose fields are expected to be of
* value types - an instance of which will be an argument to the
* {@code testUnresolvedValueTypePutField} and {@code testUnresolvedValueTypeGetField}
* methods that will be generated for the current class. Those methods will perform
* {@code PUTFIELD} or {@code GETFIELD} operations, respectively, on the fields of
* the {@code accessedContainer} instance.
*
* The intention is to test delaying resolution of the fields and their types,
* particularly its effect on code generated by the JIT compiler.
*/
public void setAccessedContainer(ClassConfiguration accessedContainer) {
this.accessedContainer = accessedContainer;
}

/**
* @see setAccessedContainer
*/
public ClassConfiguration getAccessedContainer() {
return accessedContainer;
}

/**
* This method specifies a value type class that will be used in code generated
* for the {@code testUnresolvedValueTypeDefaultValue} and
* {@code testUnresolvedValueTypeWithField} methods of the current class.
* The former will conditionally perform a {@code DEFAULTVALUE} operation on the
* value type and the latter will conditionally perform a series of
* {@code WITHFIELD} operations on the fields of an instance of the value type.
* The instance should be passed to {@code testUnresolvedValueTypeWithField} via an
* argument of type {@link java.lang.Object}.
*
* The value type class will be declared to be a {@code NestMember} of the current
* class, and must in turn declare the current class to be its {@code NestHost}.
*
* The intention is to test delayed resolution of the value type class, particularly
* its effect on code generated by the JIT compiler.
*/
public void setValueClassUsedInCode(ClassConfiguration valueClassUsedInCode) {
this.valueClassUsedInCode = valueClassUsedInCode;
}

/**
* @see setValueClassUsedInCode
*/
public ClassConfiguration getValueClassUsedInCode() {
return valueClassUsedInCode;
}
Expand Down Expand Up @@ -149,7 +190,7 @@ private static byte[] generateClass(ClassConfiguration config) {
}

if (valueUsedInCode != null) {
cw.visitNestHost(valueUsedInCode);
cw.visitNestMember(valueUsedInCode);
}

int makeMaxLocal = 0;
Expand Down Expand Up @@ -1117,15 +1158,15 @@ public static void generateClassFile(String name, byte[] bytes) {
}

public static Class<?> generateValueClass(String name, String[] fields) throws Throwable {
ClassConfiguration classConfig = new ClassConfiguration(name, fields);

byte[] bytes = generateClass(classConfig);
return generator.defineClass(name, bytes, 0, bytes.length);
return generateValueClass(name, fields, null);
}

public static Class<?> generateValueClass(String name, String[] fields, String nestHost) throws Throwable {
ClassConfiguration classConfig = new ClassConfiguration(name, fields);
classConfig.setNestHost(nestHost);

if (nestHost != null) {
classConfig.setNestHost(nestHost);
}

byte[] bytes = generateClass(classConfig);
return generator.defineClass(name, bytes, 0, bytes.length);
Expand Down
Loading

0 comments on commit fbba191

Please sign in to comment.