Skip to content

Commit

Permalink
Revert "Fix inconsistency between J9Class and annotation data when re…
Browse files Browse the repository at this point in the history
…define"
  • Loading branch information
pshipton committed Dec 2, 2021
1 parent eb2bd2a commit 06ae571
Show file tree
Hide file tree
Showing 29 changed files with 126 additions and 738 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package com.ibm.oti.reflect;

/*******************************************************************************
* Copyright (c) 2010, 2021 IBM Corp. and others
* Copyright (c) 2010, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -33,7 +33,6 @@
/*[ELSE]*/
import sun.reflect.ConstantPool;
/*[ENDIF]*/
import com.ibm.oti.vm.VM;

public class AnnotationParser {

Expand Down Expand Up @@ -74,7 +73,6 @@ public static Object parseDefaultValue(Method method) {
if (elementValueData == null) return null;
ByteBuffer buf = ByteBuffer.wrap(elementValueData);
Class clazz = method.getDeclaringClass();
Object internalConstantPool = VM.getVMLangAccess().getInternalConstantPoolFromClass(clazz);

/* The AnnotationParser boxes primitive return types */
Class returnType = method.getReturnType();
Expand All @@ -97,15 +95,14 @@ public static Object parseDefaultValue(Method method) {
returnType = Double.class;
}
}
return sun.reflect.annotation.AnnotationParser.parseMemberValue(returnType, buf, getConstantPool(internalConstantPool), clazz);
return sun.reflect.annotation.AnnotationParser.parseMemberValue(returnType, buf, getConstantPool(clazz), clazz);
}

public static Annotation[] parseAnnotations(byte[] annotationsData, Class clazz) {
Object internalConstantPool = VM.getVMLangAccess().getInternalConstantPoolFromClass(clazz);
return sun.reflect.annotation.AnnotationParser.toArray(
sun.reflect.annotation.AnnotationParser.parseAnnotations(
annotationsData,
getConstantPool(internalConstantPool),
getConstantPool(clazz),
clazz));
}

Expand All @@ -115,7 +112,7 @@ public static Annotation[] parseAnnotations(byte[] annotationsData, Class clazz)
private static native byte[] getParameterAnnotationsData(Constructor constructor);
private static native byte[] getParameterAnnotationsData(Method method);
private static native byte[] getDefaultValueData(Method method);
static native ConstantPool getConstantPool(Object internalConstantPool);
static native ConstantPool getConstantPool(Class clazz);
private static native byte[] getAnnotationsDataImpl(java.lang.Class clazz);

private static Annotation[][] parseParameterAnnotations(byte[] annotationsData, Class<?> declaringClass, int parametersCount) {
Expand All @@ -126,7 +123,6 @@ private static Annotation[][] parseParameterAnnotations(byte[] annotationsData,
}
return annotations;
}
Object internalConstantPool = VM.getVMLangAccess().getInternalConstantPoolFromClass(declaringClass);
return sun.reflect.annotation.AnnotationParser.parseParameterAnnotations(annotationsData, getConstantPool(internalConstantPool), declaringClass);
return sun.reflect.annotation.AnnotationParser.parseParameterAnnotations(annotationsData, getConstantPool(declaringClass), declaringClass);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@

import java.lang.reflect.AnnotatedType;
import java.lang.reflect.Constructor;
import com.ibm.oti.vm.VM;
/*[IF JAVA_SPEC_VERSION == 8]
import sun.misc.Unsafe;
/*[ELSE]*/
import jdk.internal.misc.Unsafe;
/*[ENDIF]*/

/*******************************************************************************
* Copyright (c) 2014, 2021 IBM Corp. and others
* Copyright (c) 2014, 2014 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -105,17 +99,7 @@ private static byte[] getAttributeData(Class clazz) {
*/
public static AnnotatedType[] buildAnnotatedInterfaces(Class clazz) {
byte[] attr = getAttributeData(clazz);
long offset = Unsafe.ARRAY_BYTE_BASE_OFFSET + ((attr.length * Unsafe.ARRAY_BYTE_INDEX_SCALE) - VM.FJ9OBJECT_SIZE);
long ramCPAddr = 0;
if (VM.FJ9OBJECT_SIZE == 4) {
/* Compressed object refs */
ramCPAddr = Integer.toUnsignedLong(Unsafe.getUnsafe().getInt(attr, offset));
} else {
ramCPAddr = Unsafe.getUnsafe().getLong(attr, offset);
}
Object internalConstantPool = VM.getVMLangAccess().createInternalConstantPool(ramCPAddr);

AnnotatedType[] annotatedInterfaces = sun.reflect.annotation.TypeAnnotationParser.buildAnnotatedInterfaces(attr, AnnotationParser.getConstantPool(internalConstantPool), clazz);
AnnotatedType[] annotatedInterfaces = sun.reflect.annotation.TypeAnnotationParser.buildAnnotatedInterfaces(attr, AnnotationParser.getConstantPool(clazz), clazz);
return annotatedInterfaces;
}
/**
Expand All @@ -125,17 +109,7 @@ public static AnnotatedType[] buildAnnotatedInterfaces(Class clazz) {
*/
public static AnnotatedType buildAnnotatedSupertype(Class clazz) {
byte[] attr = getAttributeData(clazz);
long offset = Unsafe.ARRAY_BYTE_BASE_OFFSET + ((attr.length * Unsafe.ARRAY_BYTE_INDEX_SCALE) - VM.FJ9OBJECT_SIZE);
long ramCPAddr = 0;
if (VM.FJ9OBJECT_SIZE == 4) {
/* Compressed object refs */
ramCPAddr = Integer.toUnsignedLong(Unsafe.getUnsafe().getInt(attr, offset));
} else {
ramCPAddr = Unsafe.getUnsafe().getLong(attr, offset);
}
Object internalConstantPool = VM.getVMLangAccess().createInternalConstantPool(ramCPAddr);

AnnotatedType annotatedSuperclass = sun.reflect.annotation.TypeAnnotationParser.buildAnnotatedSuperclass(attr, AnnotationParser.getConstantPool(internalConstantPool), clazz);
AnnotatedType annotatedSuperclass = sun.reflect.annotation.TypeAnnotationParser.buildAnnotatedSuperclass(attr, AnnotationParser.getConstantPool(clazz), clazz);
return annotatedSuperclass;
}
}
7 changes: 0 additions & 7 deletions jcl/src/java.base/share/classes/com/ibm/oti/vm/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,4 @@ public static int markCurrentThreadAsSystem()

private static native int markCurrentThreadAsSystemImpl();

/**
* Gets the J9ConstantPool address from a J9Class address
* @param j9clazz J9Class address
* @return Address of J9ConstantPool
*/
public static native long getJ9ConstantPoolFromJ9Class(long j9clazz);

}
36 changes: 9 additions & 27 deletions jcl/src/java.base/share/classes/com/ibm/oti/vm/VMLangAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,38 +129,20 @@ public interface VMLangAccess {
/*[ENDIF]*/

/**
* Returns an InternalConstantPool object.
*
* @param addr - the native addr of the J9ConstantPool
* @return An InternalConstantPool object
*/
public Object createInternalConstantPool(long addr);

* Returns an InternalRamClass object.
*
* @param addr - the native addr of the J9Class
* @return An InternalRamClass object
*/
public Object createInternalRamClass(long addr);
/**
* Returns a ConstantPool object
*
* @param internalConstantPool An object ref to an InternalConstantPool
* @param internalRamClass An object ref to an internalRamClass
* @return ConstantPool instance
*/
public ConstantPool getConstantPool(Object internalConstantPool);

/**
* Returns an InternalConstantPool object from a J9Class address. The ConstantPool
* natives expect an InternalConstantPool as the constantPoolOop parameter.
*
* @param j9class the native address of the J9Class
* @return InternalConstantPool a wrapper for a j9constantpool
*/
public Object getInternalConstantPoolFromJ9Class(long j9class);

/**
* Returns an InternalConstantPool object from a Class. The ConstantPool
* natives expect an InternalConstantPool as the constantPoolOop parameter.
*
* @param clazz the Class to fetch the constant pool from
* @return an InternalConstantPool wrapper for a j9constantpool
*/
public Object getInternalConstantPoolFromClass(Class clazz);
public ConstantPool getConstantPool(Object internalRamClass);

/*[IF Sidecar19-SE]*/
/**
Expand Down
16 changes: 3 additions & 13 deletions jcl/src/java.base/share/classes/java/lang/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -3349,20 +3349,10 @@ private AnnotationCache getAnnotationCache() {
if (annotationsData == null) {
annotationCacheResult = new AnnotationCache(null, buildAnnotations(null));
} else {
long offset = Unsafe.ARRAY_BYTE_BASE_OFFSET + ((annotationsData.length * Unsafe.ARRAY_BYTE_INDEX_SCALE) - VM.FJ9OBJECT_SIZE);
long ramCPAddr = 0;
if (VM.FJ9OBJECT_SIZE == 4) {
/* Compressed object refs */
ramCPAddr = Integer.toUnsignedLong(unsafe.getInt(annotationsData, offset));
} else {
ramCPAddr = unsafe.getLong(annotationsData, offset);
}
Object internalCP = VM.getVMLangAccess().createInternalConstantPool(ramCPAddr);

Annotation[] directAnnotations = sun.reflect.annotation.AnnotationParser.toArray(
sun.reflect.annotation.AnnotationParser.parseAnnotations(
annotationsData,
getConstantPool(internalCP),
getConstantPool(),
this));

LinkedHashMap<Class<? extends Annotation>, Annotation> directAnnotationsMap = new LinkedHashMap<>(directAnnotations.length * 4 / 3);
Expand Down Expand Up @@ -5059,8 +5049,8 @@ Object setMethodHandleCache(Object cache) {
return result;
}

ConstantPool getConstantPool(Object internalCP) {
return VM.getVMLangAccess().getConstantPool(internalCP);
ConstantPool getConstantPool() {
return SharedSecrets.getJavaLangAccess().getConstantPool(this);
}

/*[IF Sidecar19-SE]*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*[INCLUDE-IF Sidecar18-SE]*/
package java.lang;
/*******************************************************************************
* Copyright (c) 2017, 2021 IBM Corp. and others
* Copyright (c) 2017, 2017 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -23,14 +23,14 @@
*******************************************************************************/

/**
* Represents the internal J9ConstantPool
*
* Represents the internal J9Class
*
*/
final class InternalConstantPool {
final class InternalRamClass {
@SuppressWarnings("unused")
private final long vmref;

public InternalConstantPool(long addr) {
public InternalRamClass(long addr) {
vmref = addr;
}
}
55 changes: 12 additions & 43 deletions jcl/src/java.base/share/classes/java/lang/VMAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@


import com.ibm.oti.vm.*;
import com.ibm.jit.JITHelpers;

/**
* Helper class to allow privileged access to classes
Expand Down Expand Up @@ -186,56 +185,26 @@ public Package getSystemPackage(String name) {
/*[ENDIF]*/

/**
* Returns an InternalConstantPool object.
*
* @param addr - the native addr of the J9ConstantPool
* @return An InternalConstantPool reference object
*/
* Returns a InternalRamClass object.
*
* @param addr - the native addr of the J9Class
* @return A InternalRamClass reference object
*/
@Override
public Object createInternalConstantPool(long addr) {
return new InternalConstantPool(addr);
public Object createInternalRamClass(long addr) {
return new InternalRamClass(addr);
}

/**
* Returns a ConstantPool object
* @param internalConstantPool An object ref to a j9constantpool
* @param internalRamClass An object ref to a j9class
* @return ConstantPool instance
*/
@Override
public ConstantPool getConstantPool(Object internalConstantPool) {
return Access.getConstantPool(internalConstantPool);
}

/**
* Returns an InternalConstantPool object from a J9Class address. The ConstantPool
* natives expect an InternalConstantPool as the constantPoolOop parameter.
*
* @param j9class the native address of the J9Class
* @return InternalConstantPool a wrapper for a j9constantpool
*/
public Object getInternalConstantPoolFromJ9Class(long j9class) {
long j9constantpool = VM.getJ9ConstantPoolFromJ9Class(j9class);
return createInternalConstantPool(j9constantpool);
public ConstantPool getConstantPool(Object internalRamClass) {
return Access.getConstantPool(internalRamClass);
}

/**
* Returns an InternalConstantPool object from a Class. The ConstantPool
* natives expect an InternalConstantPool as the constantPoolOop parameter.
*
* @param clazz the Class to fetch the constant pool from
* @return an InternalConstantPool wrapper for a j9constantpool
*/
public Object getInternalConstantPoolFromClass(Class clazz) {
JITHelpers helpers = JITHelpers.getHelpers();
long j9class;
if (helpers.is32Bit()) {
j9class = helpers.getJ9ClassFromClass32(clazz);
} else {
j9class = helpers.getJ9ClassFromClass64(clazz);
}
return getInternalConstantPoolFromJ9Class(j9class);
}


/*[IF Sidecar19-SE]*/
@Override
public void addPackageToList(java.lang.Class<?> newClass, ClassLoader loader) {
Expand Down
Loading

0 comments on commit 06ae571

Please sign in to comment.