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

Issue 23616 Fixed generators on jdk11 + tests #23621

Merged
8 changes: 8 additions & 0 deletions appserver/ejb/ejb-container/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
462 changes: 158 additions & 304 deletions appserver/ejb/ejb-container/src/main/java/com/sun/ejb/EJBUtils.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -18,6 +19,7 @@

import com.sun.ejb.containers.BaseContainer;
import com.sun.ejb.EJBUtils;
import com.sun.ejb.codegen.RemoteGenerator;
import com.sun.ejb.containers.EjbContainerUtilImpl;
import com.sun.ejb.containers.RemoteBusinessWrapperBase;
import com.sun.enterprise.container.common.spi.util.JavaEEIOUtils;
Expand Down Expand Up @@ -69,6 +71,7 @@ public static final void setJavaEEIOUtils(JavaEEIOUtils javaEEIOUtils) {
* This code is needed to serialize non-Serializable objects that
* can be part of a bean's state. See EJB2.0 section 7.4.1.
*/
@Override
public Object replaceObject(Object obj)
throws IOException {
Object result = obj;
Expand Down Expand Up @@ -186,6 +189,7 @@ final class SerializableJNDIContext
}
}

@Override
public Object createObject()
throws IOException
{
Expand Down Expand Up @@ -273,6 +277,7 @@ final class SerializableS1ASEJBHomeReference
super(containerId);
}

@Override
public Object createObject()
throws IOException
{
Expand All @@ -299,14 +304,14 @@ public Object createObject()
final class SerializableS1ASEJBObjectReference
extends AbstractSerializableS1ASEJBReference
{
private byte[] instanceKey;
private final byte[] instanceKey;
private Object sfsbKey;
private long sfsbClientVersion;
private boolean haEnabled;

// If 3.0 Remote business view, the name of the remote business
// interface to which this stub corresponds.
private String remoteBusinessInterface;
private final String remoteBusinessInterface;

SerializableS1ASEJBObjectReference(long containerId, byte[] objKey,
int keySize, String remoteBusinessInterfaceName) {
Expand All @@ -330,6 +335,7 @@ boolean isHAEnabled() {
return haEnabled;
}

@Override
public Object createObject()
throws IOException
{
Expand All @@ -352,7 +358,7 @@ public Object createObject()

} else {

String generatedRemoteIntfName = EJBUtils.
String generatedRemoteIntfName = RemoteGenerator.
getGeneratedRemoteIntfName(remoteBusinessInterface);

java.rmi.Remote remoteRef = container.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -30,19 +31,31 @@
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

public class AsmSerializableBeanGenerator
implements Opcodes {
public class AsmSerializableBeanGenerator implements Opcodes {

private static final int INTF_FLAGS = ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES;

private byte[] classData = null;
private byte[] classData;
private Class loadedClass;
private final ClassLoader loader;

private Class loadedClass = null;
private ClassLoader loader;
private final Class baseClass;

private Class baseClass;
private final String subclassName;


/**
* Adds _Serializable to the original name.
*
* @param beanClass full class name
*/
public static String getGeneratedSerializableClassName(String beanClass) {
String packageName = Generator.getPackageName(beanClass);
String simpleName = Generator.getBaseName(beanClass);
String generatedSimpleName = "_" + simpleName + "_Serializable";
return packageName == null ? generatedSimpleName : packageName + "." + generatedSimpleName;
}

private String subclassName;

public AsmSerializableBeanGenerator(ClassLoader loader, Class baseClass, String serializableSubclassName) {
this.loader = loader;
Expand All @@ -51,9 +64,7 @@ public AsmSerializableBeanGenerator(ClassLoader loader, Class baseClass, String
}

public String getSerializableSubclassName() {

return subclassName;

}

public Class generateSerializableSubclass()
Expand Down Expand Up @@ -132,57 +143,13 @@ public Class generateSerializableSubclass()
cv.visitInsn(RETURN);
cv.visitMaxs(2, 2);


/**
Type[] eTypes = new Type[] { Type.getType(java.io.IOException.class)};

Method writeObjMethod = Method.getMethod("void writeObject (java.io.ObjectOutputStream)");
GeneratorAdapter writeObjMethodAdapter =
new GeneratorAdapter(ACC_PRIVATE, writeObjMethod, null, eTypes, tv);

Type ejbUtilsType = Type.getType(com.sun.ejb.EJBUtils.class);
Method ejbUtilsWrite = Method.getMethod
("void serializeObjectFields (java.lang.Class, java.lang.Object, java.lang.Object)");


writeObjMethodAdapter.push(Type.getType(ejbClass));
writeObjMethodAdapter.loadThis();
writeObjMethodAdapter.loadArg(0);

writeObjMethodAdapter.invokeStatic( ejbUtilsType, ejbUtilsWrite);

writeObjMethodAdapter.endMethod();


//
eTypes = new Type[] { Type.getType(java.io.IOException.class),
Type.getType(java.lang.ClassNotFoundException.class)};

Method readObjMethod = Method.getMethod("void readObject (java.io.ObjectInputStream)");
GeneratorAdapter readObjMethodAdapter =
new GeneratorAdapter(ACC_PRIVATE, readObjMethod, null, eTypes, tv);


Method ejbUtilsRead = Method.getMethod
("void deserializeObjectFields (java.lang.Class, java.lang.Object, java.lang.Object)");


readObjMethodAdapter.push(Type.getType(ejbClass));
readObjMethodAdapter.loadThis();
readObjMethodAdapter.loadArg(0);

readObjMethodAdapter.invokeStatic( ejbUtilsType, ejbUtilsRead);

readObjMethodAdapter.endMethod();

**/

tv.visitEnd();

classData = cw.toByteArray();

loadedClass = (Class) java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
@Override
public java.lang.Object run() {
return makeClass(subclassName, classData, baseClass.getProtectionDomain(), loader);
}
Expand All @@ -196,6 +163,7 @@ public java.lang.Object run() {
// using reflection. This requires the supressAccessChecks permission.
private static final java.lang.reflect.Method defineClassMethod = AccessController.doPrivileged(
new PrivilegedAction<java.lang.reflect.Method>() {
@Override
public java.lang.reflect.Method run() {
try {
java.lang.reflect.Method meth = ClassLoader.class.getDeclaredMethod(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -16,14 +17,26 @@

package com.sun.ejb.codegen;

import org.glassfish.pfl.dynamic.codegen.spi.Wrapper;

/** Convenience interface that defines a factory for ClassGenerator instances.
/**
* Convenience interface that defines a factory for ClassGenerator instances.
* It puts the class name of the generated class in a single place.
* It must always be the case that evaluate().name().equals( className() ).
*/
public interface ClassGeneratorFactory
{
String className() ;
public interface ClassGeneratorFactory {

/**
* @return name of the generated class or interface
*/
String getGeneratedClassName();

/**
* @return loadable class of the same package as {@link #getGeneratedClassName()}
*/
Class<?> getAnchorClass();

/**
* Calls {@link Wrapper} methods to configure the class definition.
*/
void evaluate();
}
Loading