Skip to content

Commit

Permalink
Raise bytecode level
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Pinčuk <alexander.v.pinchuk@gmail.com>
  • Loading branch information
avpinchuk committed Jan 17, 2024
1 parent d2d81aa commit 51126f2
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation.
* Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -34,7 +34,7 @@
import static org.objectweb.asm.Opcodes.ALOAD;
import static org.objectweb.asm.Opcodes.INVOKESTATIC;
import static org.objectweb.asm.Opcodes.RETURN;
import static org.objectweb.asm.Opcodes.V11;
import static org.objectweb.asm.Opcodes.V17;

public class AsmSerializableBeanGenerator extends BeanGeneratorBase {

Expand Down Expand Up @@ -70,7 +70,7 @@ public Class<?> generateSerializableSubclass() {

ClassWriter cw = new ClassWriter(0);

cw.visit(V11, ACC_PUBLIC, subClassInternalName, null, Type.getInternalName(superClass), new String[] {"java/io/Serializable"});
cw.visit(V17, ACC_PUBLIC, subClassInternalName, null, Type.getInternalName(superClass), new String[] {"java/io/Serializable"});

generateConstructor(cw, superClass, false);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation.
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -59,7 +59,7 @@
import static org.objectweb.asm.Opcodes.NEW;
import static org.objectweb.asm.Opcodes.PUTFIELD;
import static org.objectweb.asm.Opcodes.RETURN;
import static org.objectweb.asm.Opcodes.V11;
import static org.objectweb.asm.Opcodes.V17;

public class EjbOptionalIntfGenerator extends BeanGeneratorBase {

Expand Down Expand Up @@ -106,7 +106,7 @@ public void generateInterface(Class<?> ejbClass, String intfClassName, final Cla

ClassWriter cw = new ClassWriter(0);

cw.visit(V11,
cw.visit(V17,
ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE,
intfClassName.replace('.', '/'),
null,
Expand Down Expand Up @@ -169,7 +169,7 @@ public void generateSubclass(Class<?> superClass, String subClassName, Class<?>
interfaceNames[i + 1] = Type.getInternalName(interfaces[i]);
}

cw.visit(V11, ACC_PUBLIC, subClassInternalName, null, Type.getInternalName(superClass), interfaceNames);
cw.visit(V17, ACC_PUBLIC, subClassInternalName, null, Type.getInternalName(superClass), interfaceNames);

generateDelegateField(cw, fieldDesc);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2023 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 @@ -17,23 +17,9 @@

package org.glassfish.admin.rest.composite;

import static java.util.Collections.emptySet;
import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
import static org.objectweb.asm.Opcodes.ACC_SUPER;
import static org.objectweb.asm.Opcodes.ALOAD;
import static org.objectweb.asm.Opcodes.ARETURN;
import static org.objectweb.asm.Opcodes.DUP;
import static org.objectweb.asm.Opcodes.GETFIELD;
import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
import static org.objectweb.asm.Opcodes.NEW;
import static org.objectweb.asm.Opcodes.PUTFIELD;
import static org.objectweb.asm.Opcodes.RETURN;
import static org.objectweb.asm.Opcodes.V11;

import com.sun.enterprise.util.LocalStringManagerImpl;
import com.sun.enterprise.v3.common.ActionReporter;

import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
Expand All @@ -44,6 +30,7 @@
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Expand All @@ -65,7 +52,9 @@
import java.util.ResourceBundle;
import java.util.Set;
import java.util.logging.Level;

import javax.security.auth.Subject;

import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
Expand Down Expand Up @@ -93,6 +82,21 @@
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;

import static java.util.Collections.emptySet;
import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
import static org.objectweb.asm.Opcodes.ACC_SUPER;
import static org.objectweb.asm.Opcodes.ALOAD;
import static org.objectweb.asm.Opcodes.ARETURN;
import static org.objectweb.asm.Opcodes.DUP;
import static org.objectweb.asm.Opcodes.GETFIELD;
import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
import static org.objectweb.asm.Opcodes.NEW;
import static org.objectweb.asm.Opcodes.PUTFIELD;
import static org.objectweb.asm.Opcodes.RETURN;
import static org.objectweb.asm.Opcodes.V17;

/**
* @author jdlee
*/
Expand Down Expand Up @@ -732,7 +736,7 @@ private void visitClass(ClassWriter classWriter, String className, Set<Class<?>>
ifaceNames[i++] = iface.getName().replace(".", "/");
}
className = getInternalName(className);
classWriter.visit(V11, ACC_PUBLIC + ACC_SUPER, className, null, "org/glassfish/admin/rest/composite/RestModelImpl", ifaceNames);
classWriter.visit(V17, ACC_PUBLIC + ACC_SUPER, className, null, "org/glassfish/admin/rest/composite/RestModelImpl", ifaceNames);

// Add @XmlRootElement
classWriter.visitAnnotation("Ljakarta/xml/bind/annotation/XmlRootElement;", true).visitEnd();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2023 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 @@ -36,7 +36,31 @@
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;

import static org.objectweb.asm.Opcodes.*;
import static org.objectweb.asm.Opcodes.AASTORE;
import static org.objectweb.asm.Opcodes.ACC_PROTECTED;
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
import static org.objectweb.asm.Opcodes.ACC_SUPER;
import static org.objectweb.asm.Opcodes.ALOAD;
import static org.objectweb.asm.Opcodes.ANEWARRAY;
import static org.objectweb.asm.Opcodes.ARETURN;
import static org.objectweb.asm.Opcodes.ASTORE;
import static org.objectweb.asm.Opcodes.BIPUSH;
import static org.objectweb.asm.Opcodes.CHECKCAST;
import static org.objectweb.asm.Opcodes.DUP;
import static org.objectweb.asm.Opcodes.GETFIELD;
import static org.objectweb.asm.Opcodes.ICONST_0;
import static org.objectweb.asm.Opcodes.ICONST_1;
import static org.objectweb.asm.Opcodes.ICONST_2;
import static org.objectweb.asm.Opcodes.ICONST_3;
import static org.objectweb.asm.Opcodes.ICONST_4;
import static org.objectweb.asm.Opcodes.ICONST_5;
import static org.objectweb.asm.Opcodes.INVOKEINTERFACE;
import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
import static org.objectweb.asm.Opcodes.NEW;
import static org.objectweb.asm.Opcodes.POP;
import static org.objectweb.asm.Opcodes.RETURN;
import static org.objectweb.asm.Opcodes.V17;

/**
* @author Ludovic Champenois
Expand Down Expand Up @@ -70,7 +94,7 @@ public ASMClassWriter(ServiceLocator habitat, String generatedPath, String class
} else {
baseClassName = "org/glassfish/admin/rest/resources/" + baseClassName;
}
cw.visit(V11, ACC_PUBLIC + ACC_SUPER, generatedPath + className, null, baseClassName, null);
cw.visit(V17, ACC_PUBLIC + ACC_SUPER, generatedPath + className, null, baseClassName, null);

if (resourcePath != null) {
RestLogging.restLogger.log(Level.FINE, "Creating resource with path {0} (1)", resourcePath);
Expand Down Expand Up @@ -240,7 +264,7 @@ public void createCommandResourceConstructor(String commandResourceClassName, St
}
boolean isget = (httpMethod.equals("GET"));

cw.visit(V11, ACC_PUBLIC + ACC_SUPER, generatedPath + commandResourceClassName, null, baseClassName, null);
cw.visit(V17, ACC_PUBLIC + ACC_SUPER, generatedPath + commandResourceClassName, null, baseClassName, null);
// cw.visitInnerClass(generatedPath + commandResourceClassName +"$1", null, null, 0);
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 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 @@ -17,32 +17,28 @@

package org.glassfish.flashlight.impl.client;

/**
* @author Mahesh Kannan
* Started: Jul 20, 2008
* @author Byron Nevins, August 2009
*/
import com.sun.enterprise.util.SystemPropertyConstants;

import java.io.File;
import java.io.FileOutputStream;
import java.util.Collection;

import org.glassfish.flashlight.provider.FlashlightProbe;
import org.glassfish.flashlight.provider.ProbeRegistry;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.objectweb.asm.commons.Method;

import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.security.PrivilegedActionException;
import java.security.ProtectionDomain;
import java.util.Collection;

import static org.objectweb.asm.Opcodes.V11;
import static org.objectweb.asm.Opcodes.V17;

/**
* @author Mahesh Kannan
* Started: Jul 20, 2008
* @author Byron Nevins, August 2009
*/
public class BtraceClientGenerator {
private BtraceClientGenerator() {
// all static class -- no instances allowed
Expand All @@ -57,7 +53,7 @@ public static byte[] generateBtraceClientClassData(int clientID, Collection<Flas

//Define the access identifiers for the BTrace Client class
int access = Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL;
cw.visit(V11, access, generatedClassName, null,
cw.visit(V17, access, generatedClassName, null,
"java/lang/Object", null);
//Need a @OnMethod annotation, so prepare your Annotation Visitor for that
cw.visitAnnotation("Lcom/sun/btrace/annotations/BTrace;", true);
Expand Down Expand Up @@ -150,7 +146,7 @@ private static void writeClass(byte[] classData, String generatedClassName) {
fos.close();
}
catch(Exception e) {
// can't do anything...
// can't do anything...
}
}
}
Expand All @@ -167,7 +163,6 @@ private static void generateConstructor(ClassWriter cw) {
}
}


/**** Example generated class (bnevins, August 2009)
*
* package com.sun.btrace.flashlight.org.glassfish.web.admin.monitor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2023 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 @@ -17,10 +17,6 @@

package org.glassfish.flashlight.impl.core;

/**
* @author Mahesh Kannan
* Date: Jul 20, 2008
*/
import com.sun.enterprise.util.SystemPropertyConstants;
import com.sun.enterprise.util.io.FileUtils;

Expand All @@ -40,8 +36,12 @@
import org.objectweb.asm.commons.GeneratorAdapter;
import org.objectweb.asm.commons.Method;

import static org.objectweb.asm.Opcodes.V11;
import static org.objectweb.asm.Opcodes.V17;

/**
* @author Mahesh Kannan
* Date: Jul 20, 2008
*/
public class ProviderImplGenerator {
private static final Logger logger = FlashlightLoggerInfo.getLogger();

Expand Down Expand Up @@ -76,7 +76,7 @@ public byte[] generateClassData(FlashlightProbeProvider provider, Class provider

int access = Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL;
String[] interfaces = new String[]{providerClazz.getName().replace('.', '/')};
cw.visit(V11, access, generatedClassName, null, "java/lang/Object", interfaces);
cw.visit(V17, access, generatedClassName, null, "java/lang/Object", interfaces);


for (FlashlightProbe probe : provider.getProbes()) {
Expand Down

0 comments on commit 51126f2

Please sign in to comment.