Skip to content

Commit

Permalink
Startup Time Regression in persistence-3.1 Changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
anija-anil committed Feb 5, 2024
1 parent 514952e commit 80b87ca
Show file tree
Hide file tree
Showing 25 changed files with 914 additions and 828 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -58,12 +58,12 @@ protected byte[] generateClassBytes(String className) {
* }
*/
ClassWriter cw = new EclipseLinkASMClassWriter();
cw.visit(Opcodes.valueInt("ACC_PUBLIC") + Opcodes.valueInt("ACC_SUPER"), className, null, SOAP_RESPONSE_CLASSNAME_SLASHES, null);
cw.visit(Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, className, null, SOAP_RESPONSE_CLASSNAME_SLASHES, null);

MethodVisitor mv = cw.visitMethod(Opcodes.valueInt("ACC_PUBLIC"), "<init>", "()V", null, null);
mv.visitVarInsn(Opcodes.valueInt("ALOAD"), 0);
mv.visitMethodInsn(Opcodes.valueInt("INVOKESPECIAL"), SOAP_RESPONSE_CLASSNAME_SLASHES, "<init>", "()V", false);
mv.visitInsn(Opcodes.valueInt("RETURN"));
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, SOAP_RESPONSE_CLASSNAME_SLASHES, "<init>", "()V", false);
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -67,44 +67,44 @@ public byte[] writeClass(DynamicClassLoader loader, String className) throws Cla

// special-case: build sub-class of XRDynamicEntityCollection
if (className.endsWith(COLLECTION_WRAPPER_SUFFIX)) {
cw.visit(Opcodes.valueInt("ACC_PUBLIC") + Opcodes.valueInt("ACC_SUPER"), classNameAsSlashes, null, XR_DYNAMIC_ENTITY_COLLECTION_CLASSNAME_SLASHES, null);
mv = cw.visitMethod(Opcodes.valueInt("ACC_PUBLIC"), INIT, "()V", null, null);
mv.visitVarInsn(Opcodes.valueInt("ALOAD"), 0);
mv.visitMethodInsn(Opcodes.valueInt("INVOKESPECIAL"), XR_DYNAMIC_ENTITY_COLLECTION_CLASSNAME_SLASHES, INIT, "()V", false);
mv.visitInsn(Opcodes.valueInt("RETURN"));
cw.visit(Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, classNameAsSlashes, null, XR_DYNAMIC_ENTITY_COLLECTION_CLASSNAME_SLASHES, null);
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, INIT, "()V", null, null);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, XR_DYNAMIC_ENTITY_COLLECTION_CLASSNAME_SLASHES, INIT, "()V", false);
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
} else {
// public class Foo extends XRDynamicEntity {
cw.visit(Opcodes.valueInt("ACC_PUBLIC") + Opcodes.valueInt("ACC_SUPER"), classNameAsSlashes, null, XR_DYNAMIC_ENTITY_CLASSNAME_SLASHES, null);
cw.visit(Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, classNameAsSlashes, null, XR_DYNAMIC_ENTITY_CLASSNAME_SLASHES, null);

// public static XRDynamicPropertiesManager DPM = new
// XRDynamicPropertiesManager();
cw.visitField(Opcodes.valueInt("ACC_PUBLIC") + Opcodes.valueInt("ACC_STATIC"), PROPERTIES_MANAGER_FIELD, "L" + XR_DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES + ";", null, null);

mv = cw.visitMethod(Opcodes.valueInt("ACC_STATIC"), CLINIT, "()V", null, null);
mv.visitTypeInsn(Opcodes.valueInt("NEW"), XR_DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES);
mv.visitInsn(Opcodes.valueInt("DUP"));
mv.visitMethodInsn(Opcodes.valueInt("INVOKESPECIAL"), XR_DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES, INIT, "()V", false);
mv.visitFieldInsn(Opcodes.valueInt("PUTSTATIC"), classNameAsSlashes, PROPERTIES_MANAGER_FIELD, "L" + XR_DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES + ";");
mv.visitInsn(Opcodes.valueInt("RETURN"));
cw.visitField(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, PROPERTIES_MANAGER_FIELD, "L" + XR_DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES + ";", null, null);

mv = cw.visitMethod(Opcodes.ACC_STATIC, CLINIT, "()V", null, null);
mv.visitTypeInsn(Opcodes.NEW, XR_DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES);
mv.visitInsn(Opcodes.DUP);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, XR_DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES, INIT, "()V", false);
mv.visitFieldInsn(Opcodes.PUTSTATIC, classNameAsSlashes, PROPERTIES_MANAGER_FIELD, "L" + XR_DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES + ";");
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();

// public Foo() {
// super();
// }
mv = cw.visitMethod(Opcodes.valueInt("ACC_PUBLIC"), INIT, "()V", null, null);
mv.visitVarInsn(Opcodes.valueInt("ALOAD"), 0);
mv.visitMethodInsn(Opcodes.valueInt("INVOKESPECIAL"), XR_DYNAMIC_ENTITY_CLASSNAME_SLASHES, INIT, "()V", false);
mv.visitInsn(Opcodes.valueInt("RETURN"));
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, INIT, "()V", null, null);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, XR_DYNAMIC_ENTITY_CLASSNAME_SLASHES, INIT, "()V", false);
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();

// public XRDynamicPropertiesManager fetchPropertiesManager() {
mv = cw.visitMethod(Opcodes.valueInt("ACC_PUBLIC"), "fetchPropertiesManager", "()L" + XR_DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES + ";", null, null);
mv.visitFieldInsn(Opcodes.valueInt("GETSTATIC"), classNameAsSlashes, PROPERTIES_MANAGER_FIELD, "L" + XR_DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES + ";");
mv.visitInsn(Opcodes.valueInt("ARETURN"));
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "fetchPropertiesManager", "()L" + XR_DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES + ";", null, null);
mv.visitFieldInsn(Opcodes.GETSTATIC, classNameAsSlashes, PROPERTIES_MANAGER_FIELD, "L" + XR_DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES + ";");
mv.visitInsn(Opcodes.ARETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023,2024 Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -14,6 +14,7 @@
// Oracle - initial API and implementation
package org.eclipse.persistence.asm;

import org.eclipse.persistence.asm.internal.Util;
import org.eclipse.persistence.config.SystemProperties;
import org.eclipse.persistence.exceptions.ValidationException;
import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
Expand All @@ -26,25 +27,45 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

public class ASMFactory {

private final static SessionLog LOG = AbstractSessionLog.getLog();

// This block must be first - begin
public final static String ASM_SERVICE_ECLIPSELINK = "eclipselink";
public final static String ASM_SERVICE_OW2 = "ow2";

private final static String ASM_OW2_CLASS_VISITOR = "org.objectweb.asm.ClassVisitor";
private final static String ASM_ECLIPSELINK_CLASS_VISITOR = "org.eclipse.persistence.internal.libraries.asm.ClassVisitor";

//Should be changed in case of ASM upgrade
public final static int ASM_API_SELECTED = Opcodes.valueInt("ASM9");
public final static int JAVA_CLASS_VERSION = Opcodes.valueInt("V1_8");
private final static String ASM_OPCCODES_OW2 = "org.objectweb.asm.Opcodes";
private final static String ASM_OPCCODES_ECLIPSELINK = "org.eclipse.persistence.internal.libraries.asm.Opcodes";

private final static Map<String, String> ASM_OPCCODES_MAP = new HashMap<>();

static {
ASM_OPCCODES_MAP.put(ASMFactory.ASM_SERVICE_OW2, ASM_OPCCODES_OW2);
ASM_OPCCODES_MAP.put(ASMFactory.ASM_SERVICE_ECLIPSELINK, ASM_OPCCODES_ECLIPSELINK);
}

private final static SessionLog LOG = AbstractSessionLog.getLog();
// This block must be first - end

// Do not reference static fields in Opcodes to avoid circular static initialization

// Should be changed in case of ASM upgrade
public final static int ASM_API_SELECTED = valueOpcodesInt("ASM9");
public final static int JAVA_CLASS_VERSION = valueOpcodesInt("V1_8");
public final static int JAVA_CLASS_LATEST_VERSION = ASMFactory.getLatestOPCodeVersion();

private static int valueOpcodesInt(String fieldName) {
return ((int) Util.getFieldValue(ASM_OPCCODES_MAP, fieldName, Integer.TYPE));
}

public static AnnotationVisitor createAnnotationVisitor(final int api) {
String asmService = ASMFactory.getAsmService();
if (ASM_SERVICE_ECLIPSELINK.equals(asmService)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024 Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -21,6 +21,7 @@

public abstract class ClassReader {

//This block must be first - begin
private final static String ASM_CLASSREADER_ECLIPSELINK = "org.eclipse.persistence.internal.libraries.asm.ClassReader";
private final static String ASM_CLASSREADER_OW2 = "org.objectweb.asm.ClassReader";

Expand All @@ -30,8 +31,13 @@ public abstract class ClassReader {
ASM_CLASSREADER_MAP.put(ASMFactory.ASM_SERVICE_OW2, ASM_CLASSREADER_OW2);
ASM_CLASSREADER_MAP.put(ASMFactory.ASM_SERVICE_ECLIPSELINK, ASM_CLASSREADER_ECLIPSELINK);
}
//This block must be first - end

public static int valueInt(String fieldName) {
public static final int SKIP_CODE = valueInt("SKIP_CODE");
public static final int SKIP_DEBUG = valueInt("SKIP_DEBUG");
public static final int SKIP_FRAMES = valueInt("SKIP_FRAMES");

private static int valueInt(String fieldName) {
return ((int) Util.getFieldValue(ASM_CLASSREADER_MAP, fieldName, Integer.TYPE));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023,2024 Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -21,6 +21,7 @@

public abstract class ClassWriter extends ClassVisitor {

//This block must be first - begin
private final static String ASM_CLASSWRITER_ECLIPSELINK = "org.eclipse.persistence.internal.libraries.asm.ClassWriter";
private final static String ASM_CLASSWRITER_OW2 = "org.objectweb.asm.ClassWriter";

Expand All @@ -30,7 +31,9 @@ public abstract class ClassWriter extends ClassVisitor {
ASM_CLASSWRITER_MAP.put(ASMFactory.ASM_SERVICE_OW2, ASM_CLASSWRITER_OW2);
ASM_CLASSWRITER_MAP.put(ASMFactory.ASM_SERVICE_ECLIPSELINK, ASM_CLASSWRITER_ECLIPSELINK);
}
//This block must be first - end

public static final int COMPUTE_FRAMES = valueInt("COMPUTE_FRAMES");
private ClassWriter cw;
protected ClassWriter customClassWriter;

Expand Down Expand Up @@ -58,7 +61,7 @@ public ClassWriter getInternal() {
return cw;
}

public static int valueInt(String fieldName) {
private static int valueInt(String fieldName) {
return ((int) Util.getFieldValue(ASM_CLASSWRITER_MAP, fieldName, Integer.TYPE));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023,2024 Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -23,7 +23,7 @@ public class EclipseLinkASMClassWriter extends ClassWriter {
private ClassWriter classWriter;

public EclipseLinkASMClassWriter() {
this(ClassWriter.valueInt("COMPUTE_FRAMES"));
this(ClassWriter.COMPUTE_FRAMES);
}

public EclipseLinkASMClassWriter(final int flags) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023,2024 Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -22,6 +22,7 @@

public class Opcodes {

//This block must be first - begin
private final static String ASM_OPCCODES_ECLIPSELINK = "org.eclipse.persistence.internal.libraries.asm.Opcodes";
private final static String ASM_OPCCODES_OW2 = "org.objectweb.asm.Opcodes";

Expand All @@ -31,13 +32,68 @@ public class Opcodes {
ASM_OPCCODES_MAP.put(ASMFactory.ASM_SERVICE_OW2, ASM_OPCCODES_OW2);
ASM_OPCCODES_MAP.put(ASMFactory.ASM_SERVICE_ECLIPSELINK, ASM_OPCCODES_ECLIPSELINK);
}
//This block must be first - end

public static final int AASTORE = valueInt("AASTORE");
public static final int ACC_ENUM = valueInt("ACC_ENUM");
public static final int ACC_FINAL = valueInt("ACC_FINAL");
public static final int ACC_INTERFACE = valueInt("ACC_INTERFACE");
public static final int ACC_PRIVATE = valueInt("ACC_PRIVATE");
public static final int ACC_PROTECTED = valueInt("ACC_PROTECTED");
public static final int ACC_PUBLIC = valueInt("ACC_PUBLIC");
public static final int ACC_STATIC = valueInt("ACC_STATIC");
public static final int ACC_SUPER = valueInt("ACC_SUPER");
public static final int ACC_SYNTHETIC = valueInt("ACC_SYNTHETIC");
public static final int ACC_TRANSIENT = valueInt("ACC_TRANSIENT");
public static final int ACONST_NULL = valueInt("ACONST_NULL");
public static final int ALOAD = valueInt("ALOAD");
public static final int ANEWARRAY = valueInt("ANEWARRAY");
public static final int ARETURN = valueInt("ARETURN");
public static final int ASM9 = Opcodes.valueInt("ASM9");
public static final int ASTORE = valueInt("ASTORE");
public static final int BIPUSH = valueInt("BIPUSH");
public static final int CHECKCAST = valueInt("CHECKCAST");
public static final int DUP = valueInt("DUP");
public static final int F_SAME = valueInt("F_SAME");
public static final int GETFIELD = valueInt("GETFIELD");
public static final int GETSTATIC = valueInt("GETSTATIC");
public static final int GOTO = valueInt("GOTO");
public static final int ICONST_0 = valueInt("ICONST_0");
public static final int ICONST_1 = valueInt("ICONST_1");
public static final int ICONST_2 = valueInt("ICONST_2");
public static final int ICONST_3 = valueInt("ICONST_3");
public static final int ICONST_4 = valueInt("ICONST_4");
public static final int ICONST_5 = valueInt("ICONST_5");
public static final int IF_ACMPEQ = valueInt("IF_ACMPEQ");
public static final int IF_ACMPNE = valueInt("IF_ACMPNE");
public static final int IFEQ = valueInt("IFEQ");
public static final int IFNE = valueInt("IFNE");
public static final int IFNONNULL = valueInt("IFNONNULL");
public static final int IFNULL = valueInt("IFNULL");
public static final int ILOAD = valueInt("ILOAD");
public static final int INVOKEINTERFACE = valueInt("INVOKEINTERFACE");
public static final int INVOKESPECIAL = valueInt("INVOKESPECIAL");
public static final int INVOKESTATIC = valueInt("INVOKESTATIC");
public static final int INVOKEVIRTUAL = valueInt("INVOKEVIRTUAL");
public static final int IRETURN = valueInt("IRETURN");
public static final int NEW = valueInt("NEW");
public static final int POP = valueInt("POP");
public static final int PUTFIELD = valueInt("PUTFIELD");
public static final int PUTSTATIC = valueInt("PUTSTATIC");
public static final int RETURN = valueInt("RETURN");
public static final int SIPUSH = valueInt("SIPUSH");
public static final int V1_8 = Opcodes.valueInt("V1_8");
public static final int ACC_BRIDGE = Opcodes.valueInt("ACC_BRIDGE");
public static final int ISTORE = Opcodes.valueInt("ISTORE");
public static final int DLOAD = Opcodes.valueInt("DLOAD");
public static final int LLOAD = Opcodes.valueInt("LLOAD");
public static final int ASM5 = Opcodes.valueInt("ASM5");

public static int valueInt(String fieldName) {
return ((int) Util.getFieldValue(ASM_OPCCODES_MAP, fieldName, Integer.TYPE));
}

public static Integer valueInteger(String fieldName) {
return ((Integer) Util.getFieldValue(ASM_OPCCODES_MAP, fieldName, Integer.class));


private static int valueInt(String fieldName) {
return ((int) Util.getFieldValue(ASM_OPCCODES_MAP, fieldName, Integer.TYPE));
}

public static Class getOpcodesClass() {
Expand Down
Loading

0 comments on commit 80b87ca

Please sign in to comment.