Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Java 11+ #736

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/.shelf/
/.idea/
.shelf/
.idea/
/main/target/
/coverageTests/target/
/samples/java8testing/target/
Expand Down
7 changes: 4 additions & 3 deletions main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
</dependencies>
</plugin>
<plugin>
<groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><version>0.8.4</version>
<groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><version>0.8.8</version>
<executions>
<execution><id>default-prepare-agent</id><goals><goal>prepare-agent</goal></goals></execution>
<execution><id>default-report</id><goals><goal>report</goal></goals><phase>test</phase></execution>
Expand Down Expand Up @@ -206,8 +206,6 @@
<exclusions>
<exclusion><groupId>org.apiguardian</groupId><artifactId>apiguardian-api</artifactId></exclusion>
<exclusion><groupId>org.opentest4j</groupId><artifactId>opentest4j</artifactId></exclusion>
<exclusion><groupId>org.junit.platform</groupId><artifactId>junit-platform-engine</artifactId></exclusion>
<exclusion><groupId>org.junit.platform</groupId><artifactId>junit-platform-commons</artifactId></exclusion>
</exclusions>
</dependency>
<dependency>
Expand All @@ -233,5 +231,8 @@
<exclusion><groupId>org.springframework</groupId><artifactId>spring-expression</artifactId></exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.objenesis</groupId><artifactId>objenesis</artifactId><version>3.3</version>
</dependency>
</dependencies>
</project>
2 changes: 1 addition & 1 deletion main/src/mockit/asm/classes/BootstrapMethodsWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ DynamicItem addInvokeDynamicReference(
methods.setLength(position); // revert to old position

BootstrapMethodItem bsmItem = getBSMItem(hashCode);
DynamicItem result = cp.createDynamicItem(INDY, name, desc, bsmItem.index);
DynamicItem result = cp.createDynamicItem(INVOKE_DYNAMIC, name, desc, bsmItem.index);
return result;
}

Expand Down
4 changes: 2 additions & 2 deletions main/src/mockit/asm/classes/ClassWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public FieldVisitor visitField(
public MethodWriter visitMethod(
int access, @Nonnull String name, @Nonnull String desc, @Nullable String signature, @Nullable String[] exceptions
) {
boolean computeFrames = classVersion >= ClassVersion.V1_7;
boolean computeFrames = classVersion >= ClassVersion.V7;
MethodWriter method = new MethodWriter(this, access, name, desc, signature, exceptions, computeFrames);
methods.add(method);
return method;
Expand Down Expand Up @@ -268,5 +268,5 @@ public DynamicItem addInvokeDynamicReference(
return bootstrapMethodsWriter.addInvokeDynamicReference(name, desc, bsm, bsmArgs);
}

public boolean isJava6OrNewer() { return classVersion >= ClassVersion.V1_6; }
public boolean isJava6OrNewer() { return classVersion >= ClassVersion.V6; }
}
38 changes: 28 additions & 10 deletions main/src/mockit/asm/classes/ConstantPoolCopying.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,23 @@ void copyPool(@Nullable BootstrapMethodsWriter bootstrapMethods) {
private Item copyItem(int itemType) {
switch (itemType) {
case UTF8: return copyUTF8Item();
case INT: return copyIntItem();
case INTEGER: return copyIntItem();
case FLOAT: return copyFloatItem();
case LONG: return copyLongItem();
case DOUBLE: return copyDoubleItem();
case FIELD:
case METH:
case IMETH: return copyFieldOrMethodReferenceItem(itemType);
case NAME_TYPE: return copyNameAndTypeItem();
case HANDLE: return copyHandleItem();
case CONDY:
case INDY: return copyDynamicItem(itemType);
// case STR|CLASS|MTYPE:
default: return copyNameReferenceItem(itemType);
case FIELD_REF:
case METHOD_REF:
case IMETHOD_REF: return copyFieldOrMethodReferenceItem(itemType);
case NAME_TYPE: return copyNameAndTypeItem();
case METHOD_HANDLE: return copyHandleItem();
case DYNAMIC:
case INVOKE_DYNAMIC:return copyDynamicItem(itemType);
case STRING:
case CLASS:
case METHOD_TYPE: return copyNameReferenceItem(itemType);
case MODULE: return copyModule();
case PACKAGE: return copyPackage();
default: throw new IllegalArgumentException("Unknown CP type, cannot copy: " + itemType);
}
}

Expand Down Expand Up @@ -158,4 +162,18 @@ private Item copyDynamicItem(int type) {
item.set(type, name, desc, bsmIndex);
return item;
}

@Nonnull
private Item copyModule() {
int nameIndex = source.readItem();
String name = source.readNonnullUTF8(nameIndex);
return new ModuleItem(itemIndex, MODULE, name);
}

@Nonnull
private Item copyPackage() {
int nameIndex = source.readItem();
String name = source.readNonnullUTF8(nameIndex);
return new PackageItem(itemIndex, PACKAGE, name);
}
}
20 changes: 12 additions & 8 deletions main/src/mockit/asm/constantPool/ConstantPoolGeneration.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public StringItem newClassItem(@Nonnull String internalName) {
* Adds a string to the constant pool of the class being built.
* Does nothing if the constant pool already contains a similar item.
*
* @param type one of {@link ConstantPoolTypes#STR}, {@link ConstantPoolTypes#CLASS} or {@link ConstantPoolTypes#MTYPE}
* @param type one of {@link ConstantPoolTypes#STRING}, {@link ConstantPoolTypes#CLASS} or {@link ConstantPoolTypes#METHOD_TYPE}
* @param value the String value.
* @return a new or already existing string item.
*/
Expand Down Expand Up @@ -173,9 +173,9 @@ public MethodHandleItem newMethodHandleItem(@Nonnull MethodHandle methodHandle)

if (result == null) {
int tag = methodHandle.tag;
int memberType = tag == MethodHandle.Tag.INVOKEINTERFACE ? IMETH : METH;
int memberType = tag == MethodHandle.Tag.TAG_INVOKEINTERFACE ? IMETHOD_REF : METHOD_REF;
ClassMemberItem memberItem = newClassMemberItem(memberType, methodHandle.owner, methodHandle.name, methodHandle.desc);
pool.put11(HANDLE, tag).putShort(memberItem.index);
pool.put11(METHOD_HANDLE, tag).putShort(memberItem.index);

result = new MethodHandleItem(index++, reusableMethodHandleItem);
put(result);
Expand Down Expand Up @@ -213,7 +213,7 @@ private ClassMemberItem newClassMemberItem(int type, @Nonnull String owner, @Non
*/
@Nonnull
public ClassMemberItem newFieldItem(@Nonnull String owner, @Nonnull String name, @Nonnull String desc) {
return newClassMemberItem(FIELD, owner, name, desc);
return newClassMemberItem(FIELD_REF, owner, name, desc);
}

/**
Expand All @@ -228,7 +228,7 @@ public ClassMemberItem newFieldItem(@Nonnull String owner, @Nonnull String name,
*/
@Nonnull
public ClassMemberItem newMethodItem(@Nonnull String owner, @Nonnull String name, @Nonnull String desc, boolean itf) {
return newClassMemberItem(itf ? IMETH : METH, owner, name, desc);
return newClassMemberItem(itf ? IMETHOD_REF : METHOD_REF, owner, name, desc);
}

/**
Expand All @@ -245,7 +245,7 @@ public IntItem newInteger(int value) {
IntItem result = get(reusableIntItem);

if (result == null) {
pool.putByte(INT).putInt(value);
pool.putByte(INTEGER).putInt(value);

result = new IntItem(index++, reusableIntItem);
put(result);
Expand Down Expand Up @@ -361,7 +361,7 @@ private int newNameType(@Nonnull String name, @Nonnull String desc) {
@Nonnull
public Item newConstItem(@Nonnull Object cst) {
if (cst instanceof String) {
return newStringItem(STR, (String) cst);
return newStringItem(STRING, (String) cst);
}

if (cst instanceof Number) {
Expand All @@ -379,7 +379,7 @@ public Item newConstItem(@Nonnull Object cst) {

if (cst instanceof ReferenceType) {
String typeDesc = ((ReferenceType) cst).getInternalName();
return cst instanceof MethodType ? newStringItem(MTYPE, typeDesc) : newClassItem(typeDesc);
return cst instanceof MethodType ? newStringItem(METHOD_TYPE, typeDesc) : newClassItem(typeDesc);
}

if (cst instanceof PrimitiveType) {
Expand All @@ -391,6 +391,10 @@ public Item newConstItem(@Nonnull Object cst) {
return newMethodHandleItem((MethodHandle) cst);
}

if(cst instanceof DynamicItem) {
DynamicItem dynamicItem = (DynamicItem) cst;
return createDynamicItem(dynamicItem.type, dynamicItem.name, dynamicItem.desc, dynamicItem.bsmIndex);
}
throw new IllegalArgumentException("value " + cst);
}

Expand Down
4 changes: 2 additions & 2 deletions main/src/mockit/asm/constantPool/DynamicItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public final class DynamicItem extends TypeOrMemberItem
{
@Nonnegative private int bsmIndex;
@Nonnegative int bsmIndex;

public DynamicItem(@Nonnegative int index) { super(index); }

Expand All @@ -18,7 +18,7 @@ public final class DynamicItem extends TypeOrMemberItem
/**
* Sets the type, name, desc, and index of the constant or invoke dynamic item.
*
* @param type one of {@link ConstantPoolTypes#INDY} or {@link ConstantPoolTypes#CONDY}, for invoke or constant dynamic, respectively
* @param type one of {@link ConstantPoolTypes#INVOKE_DYNAMIC} or {@link ConstantPoolTypes#DYNAMIC}, for invoke or constant dynamic, respectively
* @param name the item name
* @param desc the item type descriptor
* @param index zero based index into the class attribute "BootstrapMethods".
Expand Down
2 changes: 1 addition & 1 deletion main/src/mockit/asm/constantPool/IntItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public final class IntItem extends IntValueItem
{
public IntItem(@Nonnegative int index) {
super(index);
type = INT;
type = INTEGER;
}

IntItem(@Nonnegative int index, @Nonnull IntItem item) { super(index, item); }
Expand Down
41 changes: 41 additions & 0 deletions main/src/mockit/asm/constantPool/ModuleItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package mockit.asm.constantPool;

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;

public final class ModuleItem extends Item
{
@Nonnull @SuppressWarnings("NullableProblems") String strVal;

ModuleItem() {
super(0);
strVal = "";
}

public ModuleItem(@Nonnegative int index, int type, @Nonnull String strVal) {
super(index);
set(type, strVal);
}

ModuleItem(@Nonnegative int index, @Nonnull ModuleItem item) {
super(index, item);
strVal = item.strVal;
}

@Nonnull
public String getValue() { return strVal; }

/**
* Sets this module name value.
*/
void set(int type, @Nonnull String strVal) {
this.type = type;
this.strVal = strVal;
setHashCode(strVal.hashCode());
}

@Override
boolean isEqualTo(@Nonnull Item item) {
return ((ModuleItem) item).strVal.equals(strVal);
}
}
41 changes: 41 additions & 0 deletions main/src/mockit/asm/constantPool/PackageItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package mockit.asm.constantPool;

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;

public final class PackageItem extends Item
{
@Nonnull @SuppressWarnings("NullableProblems") String strVal;

PackageItem() {
super(0);
strVal = "";
}

public PackageItem(@Nonnegative int index, int type, @Nonnull String strVal) {
super(index);
set(type, strVal);
}

PackageItem(@Nonnegative int index, @Nonnull PackageItem item) {
super(index, item);
strVal = item.strVal;
}

@Nonnull
public String getValue() { return strVal; }

/**
* Sets this package name value.
*/
void set(int type, @Nonnull String strVal) {
this.type = type;
this.strVal = strVal;
setHashCode(strVal.hashCode());
}

@Override
boolean isEqualTo(@Nonnull Item item) {
return ((PackageItem) item).strVal.equals(strVal);
}
}
3 changes: 2 additions & 1 deletion main/src/mockit/asm/controlFlow/CFGAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ private static int computeSizeVariationForFieldAccess(int fieldAccessOpcode, cha
case GETSTATIC: return doubleSizeType ? 2 : 1;
case PUTSTATIC: return doubleSizeType ? -2 : -1;
case GETFIELD: return doubleSizeType ? 1 : 0;
case PUTFIELD: default: return doubleSizeType ? -3 : -2;
case PUTFIELD: return doubleSizeType ? -3 : -2;
default: throw new IllegalArgumentException("Unknown field access opcode: " + fieldAccessOpcode);
}
}

Expand Down
Loading