From 3ef810aaa753ed40b7b0cbcb21c382170e0ec125 Mon Sep 17 00:00:00 2001 From: Kyle Aure Date: Wed, 25 Oct 2023 12:10:10 -0500 Subject: [PATCH 1/3] Update LibertyRuntimeTransformer and tests --- .../main/LibertyRuntimeTransformer.java | 2 +- .../example/bytecode/HelloWorldJava11.java | 21 ++ .../example/bytecode/HelloWorldJava17.java | 21 ++ .../example/bytecode/HelloWorldJava21.java | 21 ++ .../ibm/example/bytecode/HelloWorldJava6.java | 21 ++ .../ibm/example/bytecode/HelloWorldJava7.java | 21 ++ .../bytecode/HelloWorldJava7StaticInit.java | 29 ++ .../ibm/example/bytecode/HelloWorldJava8.java | 21 ++ .../bytecode/HelloWorldJava8Lambdas.java | 24 ++ .../bytecode/HelloWorldJava8StaticInit.java | 29 ++ .../HelloWorldJava8StaticLambdas.java | 35 ++ .../test/com/ibm/example/bytecode/README.md | 14 + .../test/com/ibm/ws/ras/RasTransformTest.java | 327 +++++++++++++----- .../example/bytecode/HelloWorldJava11.class | Bin 0 -> 829 bytes .../example/bytecode/HelloWorldJava17.class | Bin 0 -> 829 bytes .../example/bytecode/HelloWorldJava21.class | Bin 0 -> 829 bytes 16 files changed, 495 insertions(+), 91 deletions(-) create mode 100644 dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava11.java create mode 100644 dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava17.java create mode 100644 dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava21.java create mode 100644 dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava6.java create mode 100644 dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava7.java create mode 100644 dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava7StaticInit.java create mode 100644 dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8.java create mode 100644 dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8Lambdas.java create mode 100644 dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8StaticInit.java create mode 100644 dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8StaticLambdas.java create mode 100644 dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/README.md create mode 100644 dev/com.ibm.ws.ras.instrument_test/test/test data/com/ibm/example/bytecode/HelloWorldJava11.class create mode 100644 dev/com.ibm.ws.ras.instrument_test/test/test data/com/ibm/example/bytecode/HelloWorldJava17.class create mode 100644 dev/com.ibm.ws.ras.instrument_test/test/test data/com/ibm/example/bytecode/HelloWorldJava21.class diff --git a/dev/com.ibm.ws.ras.instrument/src/com/ibm/ws/ras/instrument/internal/main/LibertyRuntimeTransformer.java b/dev/com.ibm.ws.ras.instrument/src/com/ibm/ws/ras/instrument/internal/main/LibertyRuntimeTransformer.java index 006cdb43a67..d67d9f14bad 100644 --- a/dev/com.ibm.ws.ras.instrument/src/com/ibm/ws/ras/instrument/internal/main/LibertyRuntimeTransformer.java +++ b/dev/com.ibm.ws.ras.instrument/src/com/ibm/ws/ras/instrument/internal/main/LibertyRuntimeTransformer.java @@ -202,7 +202,7 @@ private static boolean isTransformPossible(byte[] bytes) { if (isJDK8WithHotReplaceBug) return classFileVersion <= Opcodes.V1_7; else - return classFileVersion <= Opcodes.V11; + return classFileVersion <= Opcodes.V17; } /** diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava11.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava11.java new file mode 100644 index 00000000000..5563baa6e8e --- /dev/null +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava11.java @@ -0,0 +1,21 @@ +package com.ibm.example.bytecode; + +public class HelloWorldJava11 { + public static void printHi() { + System.out.println("hi"); + } + + public static int addThingsStatic(int a, int b) { + int c = a + b; + return c; + } + + public int addThings(int a, int b) { + int c = a + b; + return c; + } + + public Object instancer(Class blah) throws IllegalAccessException, InstantiationException { + return blah.newInstance(); + } +} diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava17.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava17.java new file mode 100644 index 00000000000..608bf468ea2 --- /dev/null +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava17.java @@ -0,0 +1,21 @@ +package com.ibm.example.bytecode; + +public class HelloWorldJava17 { + public static void printHi() { + System.out.println("hi"); + } + + public static int addThingsStatic(int a, int b) { + int c = a + b; + return c; + } + + public int addThings(int a, int b) { + int c = a + b; + return c; + } + + public Object instancer(Class blah) throws IllegalAccessException, InstantiationException { + return blah.newInstance(); + } +} diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava21.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava21.java new file mode 100644 index 00000000000..37b5410fa2b --- /dev/null +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava21.java @@ -0,0 +1,21 @@ +package com.ibm.example.bytecode; + +public class HelloWorldJava21 { + public static void printHi() { + System.out.println("hi"); + } + + public static int addThingsStatic(int a, int b) { + int c = a + b; + return c; + } + + public int addThings(int a, int b) { + int c = a + b; + return c; + } + + public Object instancer(Class blah) throws IllegalAccessException, InstantiationException { + return blah.newInstance(); + } +} diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava6.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava6.java new file mode 100644 index 00000000000..1be09635c86 --- /dev/null +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava6.java @@ -0,0 +1,21 @@ +package com.ibm.example.bytecode; + +public class HelloWorldJava6 { + public static void printHi() { + System.out.println("hi"); + } + + public static int addThingsStatic(int a, int b) { + int c = a + b; + return c; + } + + public int addThings(int a, int b) { + int c = a + b; + return c; + } + + public Object instancer(Class blah) throws IllegalAccessException, InstantiationException { + return blah.newInstance(); + } +} diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava7.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava7.java new file mode 100644 index 00000000000..52bbb0f7a85 --- /dev/null +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava7.java @@ -0,0 +1,21 @@ +package com.ibm.example.bytecode; + +public class HelloWorldJava7 { + public static void printHi() { + System.out.println("hi"); + } + + public static int addThingsStatic(int a, int b) { + int c = a + b; + return c; + } + + public int addThings(int a, int b) { + int c = a + b; + return c; + } + + public Object instancer(Class blah) throws IllegalAccessException, InstantiationException { + return blah.newInstance(); + } +} diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava7StaticInit.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava7StaticInit.java new file mode 100644 index 00000000000..b2845d1a583 --- /dev/null +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava7StaticInit.java @@ -0,0 +1,29 @@ +package com.ibm.example.bytecode; + +public class HelloWorldJava7StaticInit { + public static final int staticint = 0; + + static String someString = new String(); + + static { + System.out.println("HiStatic"); + } + + public static void printHi() { + System.out.println("hi"); + } + + public static int addThingsStatic(int a, int b) { + int c = a + b; + return c; + } + + public int addThings(int a, int b) { + int c = a + b; + return c; + } + + public Object instancer(Class blah) throws IllegalAccessException, InstantiationException { + return blah.newInstance(); + } +} diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8.java new file mode 100644 index 00000000000..007be0c9636 --- /dev/null +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8.java @@ -0,0 +1,21 @@ +package com.ibm.example.bytecode; + +public class HelloWorldJava8 { + public static void printHi() { + System.out.println("hi"); + } + + public static int addThingsStatic(int a, int b) { + int c = a + b; + return c; + } + + public int addThings(int a, int b) { + int c = a + b; + return c; + } + + public Object instancer(Class blah) throws IllegalAccessException, InstantiationException { + return blah.newInstance(); + } +} diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8Lambdas.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8Lambdas.java new file mode 100644 index 00000000000..7fc5b0dfb5a --- /dev/null +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8Lambdas.java @@ -0,0 +1,24 @@ +package com.ibm.example.bytecode; + +import java.util.concurrent.Callable; + +public class HelloWorldJava8Lambdas { + public static void printHi() { + System.out.println("hi"); + } + + public static int addThingsStatic(int a, int b) { + Callable helloLambda = () -> "Hello"; + int c = a + b; + return c; + } + + public int addThings(int a, int b) { + int c = a + b; + return c; + } + + public Object instancer(Class blah) throws IllegalAccessException, InstantiationException { + return blah.newInstance(); + } +} diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8StaticInit.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8StaticInit.java new file mode 100644 index 00000000000..ffec5b27953 --- /dev/null +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8StaticInit.java @@ -0,0 +1,29 @@ +package com.ibm.example.bytecode; + +public class HelloWorldJava8StaticInit { + public static final int staticint = 0; + + static String someString = new String(); + + static { + System.out.println("HiStatic"); + } + + public static void printHi() { + System.out.println("hi"); + } + + public static int addThingsStatic(int a, int b) { + int c = a + b; + return c; + } + + public int addThings(int a, int b) { + int c = a + b; + return c; + } + + public Object instancer(Class blah) throws IllegalAccessException, InstantiationException { + return blah.newInstance(); + } +} diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8StaticLambdas.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8StaticLambdas.java new file mode 100644 index 00000000000..87c1b1148fe --- /dev/null +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8StaticLambdas.java @@ -0,0 +1,35 @@ +package com.ibm.example.bytecode; + +import java.util.concurrent.Callable; + +public class HelloWorldJava8StaticLambdas { + public static final Callable helloLambda = () -> "Hello"; + + public static final Converter STRING_CONVERTER; + + public static void printHi() { + System.out.println("hi"); + } + + static { + STRING_CONVERTER = (v -> v); + } + + public static int addThingsStatic(int a, int b) { + int c = a + b; + return c; + } + + public int addThings(int a, int b) { + int c = a + b; + return c; + } + + public Object instancer(Class blah) throws IllegalAccessException, InstantiationException { + return blah.newInstance(); + } + + public static interface Converter { + T convert(String param1String); + } +} diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/README.md b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/README.md new file mode 100644 index 00000000000..a6d871d9767 --- /dev/null +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/README.md @@ -0,0 +1,14 @@ +## Source files + +The classes compiled in this package are not meant to be used for testing. +Instead, they are placeholder .java files that we need to manually compile at different java levels. +The compiled classes will then be put into the `test data` directory. + +### Generate new class files + +```sh +cd com.ibm.ws.ras.instrument_test + +# TODO Add JDK 11 to your path + +javac -d "test/test data/" test/com/ibm/example/bytecode/HelloWorldJava11.java \ No newline at end of file diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/ws/ras/RasTransformTest.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/ws/ras/RasTransformTest.java index 3b43479fdcb..a2d59760302 100644 --- a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/ws/ras/RasTransformTest.java +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/ws/ras/RasTransformTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017 IBM Corporation and others. + * Copyright (c) 2017, 2023 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -13,11 +13,15 @@ package com.ibm.ws.ras; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; + import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; @@ -25,6 +29,7 @@ import java.util.Map; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; @@ -34,11 +39,75 @@ import com.ibm.ws.ras.instrument.internal.main.LibertyRuntimeTransformer; +@SuppressWarnings("deprecation") public class RasTransformTest extends LibertyRuntimeTransformer { private StaticTraceTestTransformer staticTransform = new StaticTraceTestTransformer(); - private Class makeAClassFromBytes(String name, byte[] classBytes, String packageName) throws ClassNotFoundException { + private static final HashMap majorCodeMap = new HashMap<>(); + + @BeforeClass + public static void setup() { + //Adapted from https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-4.html#jvms-4.1 + majorCodeMap.put("1.0.2", 45); + majorCodeMap.put("1.1", 45); + majorCodeMap.put("1.2", 46); + majorCodeMap.put("1.3", 47); + majorCodeMap.put("1.4", 48); + majorCodeMap.put("5.0", 49); + majorCodeMap.put("6", 50); + majorCodeMap.put("7", 51); + majorCodeMap.put("8", 52); + majorCodeMap.put("9", 53); + majorCodeMap.put("10", 54); + majorCodeMap.put("11", 55); + majorCodeMap.put("12", 56); + majorCodeMap.put("13", 57); + majorCodeMap.put("14", 58); + majorCodeMap.put("15", 59); + majorCodeMap.put("16", 60); + majorCodeMap.put("17", 61); + majorCodeMap.put("18", 62); + majorCodeMap.put("19", 63); + majorCodeMap.put("20", 64); + majorCodeMap.put("21", 65); + } + + /** + * Ensure the class file is compiled at the correct byte code version + * + * @param filename - path to class file to be loaded + * @param expected - the expected major version code + * @return true if the class file is compiled to the correct byte code version, false otherwise. + */ + private boolean assertByteCodeVersion(String filename, int expected) { + try ( DataInputStream in = new DataInputStream(new FileInputStream(filename)) ) { + int magic = in.readInt(); + + if(magic != 0xcafebabe) { + System.out.println(filename + " is not a valid class!"); + return false; + } + + int minor = in.readUnsignedShort(); + int major = in.readUnsignedShort(); + + System.out.println("Major version: " + major); + System.out.println("Minor version: " + minor); + + if(expected != major) { + System.out.println("Expected major version of " + expected + " but got " + major); + return false; + } + + return true; + } catch (IOException e) { + e.printStackTrace(); + return false; + } + } + + private Class makeAClassFromBytes(String name, byte[] classBytes, String packageName) throws ClassNotFoundException { Map classDefs = new HashMap(); classDefs.put(name, classBytes); @@ -46,13 +115,12 @@ private Class makeAClassFromBytes(String name, byte[] classBytes, String package testLoader.setPackage(packageName); - Class loadedClass = testLoader.loadClass(name); + Class loadedClass = testLoader.loadClass(name); try { testLoader.close(); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); } @@ -94,7 +162,7 @@ private String dumpClassViaASM(byte[] classBytes) { reader.accept(visitor, ClassReader.SKIP_DEBUG); } catch (Throwable t) { - IOException ioe = new IOException("Unable to trace class data: " + t.getMessage(), t); + t.printStackTrace(); } return sw.toString(); @@ -112,92 +180,119 @@ public String unrollStack(StackTraceElement[] trace) { @Test public void testJava6BasicInjection() { + assumeTrue(Integer.parseInt(System.getProperty("java.specification.version")) >= 6); + String classPath = "test/test data/com/ibm/example/bytecode/HelloWorldJava6.class"; + assertTrue(assertByteCodeVersion(classPath, majorCodeMap.get("6"))); + try { String classUnderTest = "com.ibm.example.bytecode.HelloWorldJava6"; - Class transformedClass = transformClass(classUnderTest, "test/test data/com/ibm/example/bytecode/HelloWorldJava6.class"); + Class transformedClass = transformClass(classUnderTest, classPath); transformedClass.newInstance(); } catch (Exception e) { - System.out.println("Exception: " + e.getStackTrace().toString()); + fail(e.getMessage()); } } @Test public void testJava7BasicInjection() { + assumeTrue(Integer.parseInt(System.getProperty("java.specification.version")) >= 7); + String classPath = "test/test data/com/ibm/example/bytecode/HelloWorldJava7.class"; + assertTrue(assertByteCodeVersion(classPath, majorCodeMap.get("7"))); + try { String classUnderTest = "com.ibm.example.bytecode.HelloWorldJava7"; - Class transformedClass = transformClass(classUnderTest, "test/test data/com/ibm/example/bytecode/HelloWorldJava7.class"); + Class transformedClass = transformClass(classUnderTest, classPath); transformedClass.newInstance(); } catch (Exception e) { - System.out.println("Exception: " + e.getStackTrace().toString()); + fail(e.getMessage()); } } @Test public void testJava7StaticInit() { + assumeTrue(Integer.parseInt(System.getProperty("java.specification.version")) >= 7); + String classPath = "test/test data/com/ibm/example/bytecode/HelloWorldJava7StaticInit.class"; + assertTrue(assertByteCodeVersion(classPath, majorCodeMap.get("7"))); + try { String classUnderTest = "com.ibm.example.bytecode.HelloWorldJava7StaticInit"; - Class transformedClass = transformClass(classUnderTest, "test/test data/com/ibm/example/bytecode/HelloWorldJava7StaticInit.class"); + Class transformedClass = transformClass(classUnderTest, classPath); transformedClass.newInstance(); } catch (Exception e) { - System.out.println("Exception: " + e.getStackTrace().toString()); + fail(e.getMessage()); } } - //Turn the java8 tests on when I figure out how to get this Unit running conditionally only on java8 tests. - //@Test + @Test public void testJava8Basic() { + assumeTrue(Integer.parseInt(System.getProperty("java.specification.version")) >= 8); + String classPath = "test/test data/com/ibm/example/bytecode/HelloWorldJava8.class"; + assertTrue(assertByteCodeVersion(classPath, majorCodeMap.get("8"))); + try { String classUnderTest = "com.ibm.example.bytecode.HelloWorldJava8"; - Class transformedClass = transformClass(classUnderTest, "test/test data/com/ibm/example/bytecode/HelloWorldJava8.class"); + Class transformedClass = transformClass(classUnderTest, classPath); transformedClass.newInstance(); } catch (Exception e) { - System.out.println("Exception: " + e.getStackTrace().toString()); + fail(e.getMessage()); } } - //@Test + @Test public void testJava8Lambdas() { + assumeTrue(Integer.parseInt(System.getProperty("java.specification.version")) >= 8); + String classPath = "test/test data/com/ibm/example/bytecode/HelloWorldJava8Lambdas.class"; + assertTrue(assertByteCodeVersion(classPath, majorCodeMap.get("8"))); + try { String classUnderTest = "com.ibm.example.bytecode.HelloWorldJava8Lambdas"; - Class transformedClass = transformClass(classUnderTest, "test/test data/com/ibm/example/bytecode/HelloWorldJava8Lambdas.class"); + Class transformedClass = transformClass(classUnderTest, classPath); transformedClass.newInstance(); } catch (Exception e) { - System.out.println("Exception: " + e.getStackTrace().toString()); + fail(e.getMessage()); } } - //@Test + @Test public void testJava8StaticInit() { + assumeTrue(Integer.parseInt(System.getProperty("java.specification.version")) >= 8); + String classPath = "test/test data/com/ibm/example/bytecode/HelloWorldJava8StaticInit.class"; + assertTrue(assertByteCodeVersion(classPath, majorCodeMap.get("8"))); + try { String classUnderTest = "com.ibm.example.bytecode.HelloWorldJava8StaticInit"; - Class transformedClass = transformClass(classUnderTest, "test/test data/com/ibm/example/bytecode/HelloWorldJava8StaticInit.class"); + Class transformedClass = transformClass(classUnderTest, classPath); transformedClass.newInstance(); } catch (Exception e) { - System.out.println("Exception: " + e.getStackTrace().toString()); + fail(e.getMessage()); } } - //@Test +// @Test TODO this test is failing public void testJava8StaticInitLambdasWithInnerClass() { + assumeTrue(Integer.parseInt(System.getProperty("java.specification.version")) >= 8); + String classPath = "test/test data/com/ibm/example/bytecode/HelloWorldJava8StaticLambdas.class"; + assertTrue(assertByteCodeVersion(classPath, majorCodeMap.get("8"))); + try { String classUnderTest = "com.ibm.example.bytecode.HelloWorldJava8StaticLambdas"; String classUnderTestInnerClass = "com.ibm.example.bytecode.HelloWorldJava8StaticLambdas$Converter"; - byte[] preTransformBytes = makeBytesFromFile("test/test data/com/ibm/example/bytecode/HelloWorldJava8StaticLambdas.class"); - byte[] preTransformBytesInnerClass = makeBytesFromFile("test/test data/com/ibm/example/bytecode/HelloWorldJava8StaticLambdas$Converter.class"); + byte[] preTransformBytes = makeBytesFromFile(classPath); + byte[] preTransformBytesInnerClass = makeBytesFromFile(classPath + "$Converter.class"); Map classDefsPreTransform = new HashMap(); classDefsPreTransform.put(classUnderTest, preTransformBytes); @@ -206,13 +301,13 @@ public void testJava8StaticInitLambdasWithInnerClass() { ByteArrayClassLoader testLoaderPreTransform = new ByteArrayClassLoader(getClass().getClassLoader(), classDefsPreTransform); testLoaderPreTransform.setPackage("com.ibm.example.bytecode"); - Class loadedClassPreTransform = testLoaderPreTransform.loadClass(classUnderTest); + Class loadedClassPreTransform = testLoaderPreTransform.loadClass(classUnderTest); loadedClassPreTransform.newInstance(); - byte[] classUnderTestBytes = transformedClassBytes(classUnderTest, "test/test data/com/ibm/example/bytecode/HelloWorldJava8StaticLambdas.class"); - byte[] classUnderTestBytesInnerClass = transformedClassBytes(classUnderTestInnerClass, "test/test data/com/ibm/example/bytecode/HelloWorldJava8StaticLambdas$Converter.class"); + byte[] classUnderTestBytes = transformedClassBytes(classUnderTest, classPath); + byte[] classUnderTestBytesInnerClass = transformedClassBytes(classUnderTestInnerClass, classPath + "$Converter.class"); Map classDefs = new HashMap(); classDefs.put(classUnderTest, classUnderTestBytes); @@ -220,32 +315,87 @@ public void testJava8StaticInitLambdasWithInnerClass() { ByteArrayClassLoader testLoader = new ByteArrayClassLoader(getClass().getClassLoader(), classDefs); testLoader.setPackage("com.ibm.example.bytecode"); - Class loadedClass = testLoader.loadClass(classUnderTest); + Class loadedClass = testLoader.loadClass(classUnderTest); loadedClass.newInstance(); } catch (Exception e) { - System.out.println("Exception: " + e.getMessage() + " " + unrollStack(e.getStackTrace())); + fail(e.getMessage()); } } - //@Test + @Test public void testJava8LambdaInjection() { + assumeTrue(Integer.parseInt(System.getProperty("java.specification.version")) >= 8); + String classPath = "test/test data/com/ibm/example/bytecode/HelloWorldJava8Lambdas.class"; + assertTrue(assertByteCodeVersion(classPath, majorCodeMap.get("8"))); + try { String classUnderTest = "com.ibm.example.bytecode.HelloWorldJava8Lambdas"; - Class transformedClass = transformClass(classUnderTest, "test/test data/com/ibm/example/bytecode/HelloWorldJava8Lambdas.class"); + Class transformedClass = transformClass(classUnderTest, classPath); transformedClass.newInstance(); } catch (Exception e) { - System.out.println("Exception: " +unrollStack(e.getStackTrace())); + fail(e.getMessage()); + } + + } + + @Test //TODO expand this test to actually test Java 11 features + public void testJava11Basic() { + assumeTrue(Integer.parseInt(System.getProperty("java.specification.version")) >= 11); + String classPath = "test/test data/com/ibm/example/bytecode/HelloWorldJava11.class"; + assertTrue(assertByteCodeVersion(classPath, majorCodeMap.get("11"))); + + try { + String classUnderTest = "com.ibm.example.bytecode.HelloWorldJava11"; + Class transformedClass = transformClass(classUnderTest, classPath); + + transformedClass.newInstance(); + } catch (Exception e) { + fail(e.getMessage()); } } + @Test //TODO expand this test to actually test Java 17 features + public void testJava17Basic() { + assumeTrue(Integer.parseInt(System.getProperty("java.specification.version")) >= 17); + String classPath = "test/test data/com/ibm/example/bytecode/HelloWorldJava17.class"; + assertTrue(assertByteCodeVersion(classPath, majorCodeMap.get("17"))); + + try { + String classUnderTest = "com.ibm.example.bytecode.HelloWorldJava17"; + Class transformedClass = transformClass(classUnderTest, classPath); + + transformedClass.newInstance(); + } catch (Exception e) { + fail(e.getMessage()); + } + + } + + //TODO update transformer to support Java 21 +// @Test //TODO expand this test to actually test Java 21 features + public void testJava21Basic() { + assumeTrue(Integer.parseInt(System.getProperty("java.specification.version")) >= 21); + String classPath = "test/test data/com/ibm/example/bytecode/HelloWorldJava21.class"; + assertTrue(assertByteCodeVersion(classPath, majorCodeMap.get("21"))); + + try { + String classUnderTest = "com.ibm.example.bytecode.HelloWorldJava21"; + Class transformedClass = transformClass(classUnderTest, classPath); + + transformedClass.newInstance(); + } catch (Exception e) { + fail(e.getMessage()); + } + + } private void writeStringToFile(String toWrite, String path) { @@ -255,69 +405,67 @@ private void writeStringToFile(String toWrite, String path) { file.println(toWrite); file.close(); } catch (FileNotFoundException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } - private void writeBytesToFile(byte[] toWrite, String path) { - try { - FileOutputStream fos = new FileOutputStream(path); - fos.write(toWrite); - fos.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } +// private void writeBytesToFile(byte[] toWrite, String path) { +// try { +// FileOutputStream fos = new FileOutputStream(path); +// fos.write(toWrite); +// fos.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } //turn this on to get detailed ASM output in the project folder. public final boolean dumpTrace = false; - private byte[] transformedClassBytesJava8Injector(String className, String path) { - byte[] transformedClass = null; - - try { - //LibertyRuntimeTransformer.setInjectAtTransform(false); - - String classUnderTest = className; - byte[] pre = makeBytesFromFile(path); - byte[] staticInject = staticTransform.transform(pre); - byte[] postDynamic = LibertyRuntimeTransformer.transform(pre, false); - - //Case that tries to fully emulate what the runtime ends up doing. - if (staticInject == null) { - staticInject = pre; - } - byte[] post = LibertyRuntimeTransformer.transform(staticInject, false); - - String preTransform = dumpClassViaASM(pre); - //System.out.println("Pre transform class: " + preTransform); - - String postStaticTransform = dumpClassViaASM(staticInject); - //System.out.println("Static transform class: " + postStaticTransform); - - String postDynamicTransform = dumpClassViaASM(postDynamic); - //System.out.println("Post transform class: " + postTransform); - - String postStaticAndDynamicTransform = dumpClassViaASM(post); - - if (dumpTrace) { - writeStringToFile(preTransform, "Debug-Pre-"+className); - writeStringToFile(postStaticTransform, "Debug-Static-"+className); - writeStringToFile(postDynamicTransform, "Debug-PostDyn-"+className); - writeStringToFile(postStaticAndDynamicTransform, "Debug-PostStaticDyn-"+className); - } - transformedClass = post; - } catch (Exception e) { - System.out.println("Exception: " + e.getStackTrace().toString()); - Assert.assertTrue(false); - } - - return transformedClass; - - } +// private byte[] transformedClassBytesJava8Injector(String className, String path) { +// byte[] transformedClass = null; +// +// try { +// //LibertyRuntimeTransformer.setInjectAtTransform(false); +// +// String classUnderTest = className; +// byte[] pre = makeBytesFromFile(path); +// byte[] staticInject = staticTransform.transform(pre); +// byte[] postDynamic = LibertyRuntimeTransformer.transform(pre, false); +// +// //Case that tries to fully emulate what the runtime ends up doing. +// if (staticInject == null) { +// staticInject = pre; +// } +// byte[] post = LibertyRuntimeTransformer.transform(staticInject, false); +// +// String preTransform = dumpClassViaASM(pre); +// //System.out.println("Pre transform class: " + preTransform); +// +// String postStaticTransform = dumpClassViaASM(staticInject); +// //System.out.println("Static transform class: " + postStaticTransform); +// +// String postDynamicTransform = dumpClassViaASM(postDynamic); +// //System.out.println("Post transform class: " + postTransform); +// +// String postStaticAndDynamicTransform = dumpClassViaASM(post); +// +// if (dumpTrace) { +// writeStringToFile(preTransform, "Debug-Pre-"+className); +// writeStringToFile(postStaticTransform, "Debug-Static-"+className); +// writeStringToFile(postDynamicTransform, "Debug-PostDyn-"+className); +// writeStringToFile(postStaticAndDynamicTransform, "Debug-PostStaticDyn-"+className); +// } +// transformedClass = post; +// } catch (Exception e) { +// System.out.println("Exception: " + e.getStackTrace().toString()); +// Assert.assertTrue(false); +// } +// +// return transformedClass; +// +// } private byte[] transformedClassBytes(String className, String path) { byte[] transformedClass = null; @@ -325,7 +473,6 @@ private byte[] transformedClassBytes(String className, String path) { try { //LibertyRuntimeTransformer.setInjectAtTransform(false); - String classUnderTest = className; byte[] pre = makeBytesFromFile(path); byte[] staticInject = staticTransform.transform(pre); byte[] postDynamic = LibertyRuntimeTransformer.transform(pre, false); @@ -363,8 +510,8 @@ private byte[] transformedClassBytes(String className, String path) { } - private Class transformClass(String className, String path) { - Class transformedClass = null; + private Class transformClass(String className, String path) { + Class transformedClass = null; try { transformedClass = makeAClassFromBytes(className, transformedClassBytes(className, path), "com.ibm.example.bytecode"); diff --git a/dev/com.ibm.ws.ras.instrument_test/test/test data/com/ibm/example/bytecode/HelloWorldJava11.class b/dev/com.ibm.ws.ras.instrument_test/test/test data/com/ibm/example/bytecode/HelloWorldJava11.class new file mode 100644 index 0000000000000000000000000000000000000000..f7a7f348e9fe28e7aed2a7e0bdeb6b73b3e26889 GIT binary patch literal 829 zcmZuvT~8B16g|_grE8@~!4KLhpw%uIH$3@JB{4)p4N;O3ePz0xlp(XT&F)m;Klz|O zVB&*6fFDJ?vn%}|?!)ZNx#yle_sm{i{r&^sC7!!*aIcK}c(8yq7j-mTH1W{EBM0jY zrB_l*v&)cgd!HBzd(l8JR1c&UAI4!{#7DfZ2ysTS)Mj5&jSmJ#CsGfSp5aCY48?Z0 z>vb8*lM3ynP7K$9h#6Y#gH!&6`-D1a`h$%M3PMW&QsFKjihiQJwurh z?wuz_gcN!-HZ)fjhK&3}8*v2Q{QZ^)J1pFv6on#+D+4DxTVF{ z?!OCRSZV(!er%vbzlwc|U^Y`)T{<=C%`Ce03+xANNRHN03g(GcnNVBEQ3WXfL~c2M zfx?vTrllh3mWX~Ei_~t_Hwn+vyR=q6e%<&+yG%agmr)=VO*F?ZSbn{6yxY9VUnG8& k_)EA$y4UWlsp9qpir**lnfn@+trSsfSfRF6I^}TpFX}?AqW}N^ literal 0 HcmV?d00001 diff --git a/dev/com.ibm.ws.ras.instrument_test/test/test data/com/ibm/example/bytecode/HelloWorldJava17.class b/dev/com.ibm.ws.ras.instrument_test/test/test data/com/ibm/example/bytecode/HelloWorldJava17.class new file mode 100644 index 0000000000000000000000000000000000000000..78f977f5cabb159dfc81e1a76aee15353a66b011 GIT binary patch literal 829 zcmZvaT~8B16o%jF*LIgmky1aPRYa>@FmAl^qC#Sbh8m(IC3wqpJ1IkEXPe!r!hiBY zy}-l^e}F&Ac&3XjCG5rSd_41<_iX0R-(SB0Y~#6y9P$nd6%f1e z!Y-{-v3;qld~R9$}5HihYWpmQbR1lV(l&GP}C@6YM(;7#`5uZUcF^csNB{mjd?(oaI{= zsLpVE4XwFMu#0u7mf1J#^|ZRxwd3u^R~lvdjCWChM=Kk1e8KW-jpLo>b$*ffD)Eo; gguMULPbzO+p#E*D&(hb>vMNHKqD{v(X_mv*KhXoOQUCw| literal 0 HcmV?d00001 diff --git a/dev/com.ibm.ws.ras.instrument_test/test/test data/com/ibm/example/bytecode/HelloWorldJava21.class b/dev/com.ibm.ws.ras.instrument_test/test/test data/com/ibm/example/bytecode/HelloWorldJava21.class new file mode 100644 index 0000000000000000000000000000000000000000..9f2f2e584997f16268c378e07020528ea69f3a5a GIT binary patch literal 829 zcmZvaT~8B16o%jF*LIgmky1aPRYa>@FmCj=N zQor8y3tI+{utrzKK1EPVDABt~vnG9+UETZ%_MHX{59n>TfjnG1oT9Buf%^l_@~sP0 zXSltF)?6mo#X42X>>KuaTHWf}@tek18fE&7cTs>xD;sls!SZX3 Date: Thu, 26 Oct 2023 11:58:11 -0500 Subject: [PATCH 2/3] Feedback and updates --- .../test/com/ibm/ws/ras/RasTransformTest.java | 128 +++++++----------- 1 file changed, 49 insertions(+), 79 deletions(-) diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/ws/ras/RasTransformTest.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/ws/ras/RasTransformTest.java index a2d59760302..9a233e7fd24 100644 --- a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/ws/ras/RasTransformTest.java +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/ws/ras/RasTransformTest.java @@ -25,10 +25,10 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; -import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.objectweb.asm.ClassReader; @@ -71,6 +71,7 @@ public static void setup() { majorCodeMap.put("19", 63); majorCodeMap.put("20", 64); majorCodeMap.put("21", 65); + majorCodeMap.put("22", 65); } /** @@ -190,6 +191,7 @@ public void testJava6BasicInjection() { transformedClass.newInstance(); } catch (Exception e) { + e.printStackTrace(); fail(e.getMessage()); } @@ -207,6 +209,7 @@ public void testJava7BasicInjection() { transformedClass.newInstance(); } catch (Exception e) { + e.printStackTrace(); fail(e.getMessage()); } @@ -224,6 +227,7 @@ public void testJava7StaticInit() { transformedClass.newInstance(); } catch (Exception e) { + e.printStackTrace(); fail(e.getMessage()); } @@ -242,6 +246,7 @@ public void testJava8Basic() { transformedClass.newInstance(); } catch (Exception e) { + e.printStackTrace(); fail(e.getMessage()); } @@ -259,6 +264,7 @@ public void testJava8Lambdas() { transformedClass.newInstance(); } catch (Exception e) { + e.printStackTrace(); fail(e.getMessage()); } @@ -276,6 +282,7 @@ public void testJava8StaticInit() { transformedClass.newInstance(); } catch (Exception e) { + e.printStackTrace(); fail(e.getMessage()); } @@ -303,11 +310,9 @@ public void testJava8StaticInitLambdasWithInnerClass() { Class loadedClassPreTransform = testLoaderPreTransform.loadClass(classUnderTest); loadedClassPreTransform.newInstance(); - - - byte[] classUnderTestBytes = transformedClassBytes(classUnderTest, classPath); - byte[] classUnderTestBytesInnerClass = transformedClassBytes(classUnderTestInnerClass, classPath + "$Converter.class"); + byte[] classUnderTestBytes = transformedClassBytes(classUnderTest, classPath, preTransformBytes); + byte[] classUnderTestBytesInnerClass = transformedClassBytes(classUnderTestInnerClass, classPath + "$Converter.class", preTransformBytesInnerClass); Map classDefs = new HashMap(); classDefs.put(classUnderTest, classUnderTestBytes); @@ -321,6 +326,7 @@ public void testJava8StaticInitLambdasWithInnerClass() { } catch (Exception e) { + e.printStackTrace(); fail(e.getMessage()); } @@ -340,12 +346,13 @@ public void testJava8LambdaInjection() { } catch (Exception e) { + e.printStackTrace(); fail(e.getMessage()); } } - @Test //TODO expand this test to actually test Java 11 features + @Test //TODO expand this test to actually test Java 11 features https://openjdk.org/jeps/323 public void testJava11Basic() { assumeTrue(Integer.parseInt(System.getProperty("java.specification.version")) >= 11); String classPath = "test/test data/com/ibm/example/bytecode/HelloWorldJava11.class"; @@ -357,12 +364,13 @@ public void testJava11Basic() { transformedClass.newInstance(); } catch (Exception e) { + e.printStackTrace(); fail(e.getMessage()); } } - @Test //TODO expand this test to actually test Java 17 features + @Test //TODO expand this test to actually test Java 17 features https://openjdk.org/jeps/409 public void testJava17Basic() { assumeTrue(Integer.parseInt(System.getProperty("java.specification.version")) >= 17); String classPath = "test/test data/com/ibm/example/bytecode/HelloWorldJava17.class"; @@ -374,13 +382,15 @@ public void testJava17Basic() { transformedClass.newInstance(); } catch (Exception e) { + e.printStackTrace(); fail(e.getMessage()); } } - //TODO update transformer to support Java 21 -// @Test //TODO expand this test to actually test Java 21 features + //FIXME - This test is currently failing because isTransformPossible returns false + //TODO expand this test to actually test Java 21 features https://openjdk.org/jeps/441 + //@Test public void testJava21Basic() { assumeTrue(Integer.parseInt(System.getProperty("java.specification.version")) >= 21); String classPath = "test/test data/com/ibm/example/bytecode/HelloWorldJava21.class"; @@ -392,6 +402,7 @@ public void testJava21Basic() { transformedClass.newInstance(); } catch (Exception e) { + e.printStackTrace(); fail(e.getMessage()); } @@ -399,81 +410,25 @@ public void testJava21Basic() { private void writeStringToFile(String toWrite, String path) { - PrintWriter file; - try { - file = new PrintWriter(path); + File dir = new File(path).getParentFile(); + dir.mkdirs(); + + try (PrintWriter file = new PrintWriter(path)) { file.println(toWrite); - file.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } -// private void writeBytesToFile(byte[] toWrite, String path) { -// try { -// FileOutputStream fos = new FileOutputStream(path); -// fos.write(toWrite); -// fos.close(); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// } - - //turn this on to get detailed ASM output in the project folder. public final boolean dumpTrace = false; -// private byte[] transformedClassBytesJava8Injector(String className, String path) { -// byte[] transformedClass = null; -// -// try { -// //LibertyRuntimeTransformer.setInjectAtTransform(false); -// -// String classUnderTest = className; -// byte[] pre = makeBytesFromFile(path); -// byte[] staticInject = staticTransform.transform(pre); -// byte[] postDynamic = LibertyRuntimeTransformer.transform(pre, false); -// -// //Case that tries to fully emulate what the runtime ends up doing. -// if (staticInject == null) { -// staticInject = pre; -// } -// byte[] post = LibertyRuntimeTransformer.transform(staticInject, false); -// -// String preTransform = dumpClassViaASM(pre); -// //System.out.println("Pre transform class: " + preTransform); -// -// String postStaticTransform = dumpClassViaASM(staticInject); -// //System.out.println("Static transform class: " + postStaticTransform); -// -// String postDynamicTransform = dumpClassViaASM(postDynamic); -// //System.out.println("Post transform class: " + postTransform); -// -// String postStaticAndDynamicTransform = dumpClassViaASM(post); -// -// if (dumpTrace) { -// writeStringToFile(preTransform, "Debug-Pre-"+className); -// writeStringToFile(postStaticTransform, "Debug-Static-"+className); -// writeStringToFile(postDynamicTransform, "Debug-PostDyn-"+className); -// writeStringToFile(postStaticAndDynamicTransform, "Debug-PostStaticDyn-"+className); -// } -// transformedClass = post; -// } catch (Exception e) { -// System.out.println("Exception: " + e.getStackTrace().toString()); -// Assert.assertTrue(false); -// } -// -// return transformedClass; -// -// } - - private byte[] transformedClassBytes(String className, String path) { + private byte[] transformedClassBytes(String className, String path, byte[] pre) { byte[] transformedClass = null; try { //LibertyRuntimeTransformer.setInjectAtTransform(false); - byte[] pre = makeBytesFromFile(path); byte[] staticInject = staticTransform.transform(pre); byte[] postDynamic = LibertyRuntimeTransformer.transform(pre, false); @@ -495,15 +450,15 @@ private byte[] transformedClassBytes(String className, String path) { String postStaticAndDynamicTransform = dumpClassViaASM(post); if (dumpTrace) { - writeStringToFile(preTransform, "Debug-Pre-"+className); - writeStringToFile(postStaticTransform, "Debug-Static-"+className); - writeStringToFile(postDynamicTransform, "Debug-PostDyn-"+className); - writeStringToFile(postStaticAndDynamicTransform, "Debug-PostStaticDyn-"+className); + writeStringToFile(preTransform, "build/results/Debug-Pre-"+className); + writeStringToFile(postStaticTransform, "build/results/Debug-Static-"+className); + writeStringToFile(postDynamicTransform, "build/results/Debug-PostDyn-"+className); + writeStringToFile(postStaticAndDynamicTransform, "build/results/Debug-PostStaticDyn-"+className); } transformedClass = post; } catch (Exception e) { - System.out.println("Exception: " + e.getStackTrace().toString()); - Assert.assertTrue(false); + e.printStackTrace(); + fail(e.getMessage()); } return transformedClass; @@ -514,14 +469,29 @@ private Class transformClass(String className, String path) { Class transformedClass = null; try { - transformedClass = makeAClassFromBytes(className, transformedClassBytes(className, path), "com.ibm.example.bytecode"); + byte[] pre = makeBytesFromFile(path); + assertTrue("isTransformPossible returned false, likely the bytecode level is not supported yet and needs to be tested", + invokeIsTransformPossible(pre)); + transformedClass = makeAClassFromBytes(className, transformedClassBytes(className, path, pre), "com.ibm.example.bytecode"); } catch (Exception e) { - System.out.println("Exception: " + e.getStackTrace().toString()); - Assert.assertTrue(false); + e.printStackTrace(); + fail(e.getMessage()); } return transformedClass; } + /** + * Invokes LibertyRuntimeTransformer.isTransformPossible() which is a private method not accessable from child class. + * + * @return the result of invoking the method + * @throws Exception if method cannot be invoked + */ + private boolean invokeIsTransformPossible(byte[] bytes) throws Exception { + Method isTransformPossible = LibertyRuntimeTransformer.class.getDeclaredMethod("isTransformPossible", byte[].class); + isTransformPossible.setAccessible(true); + return (boolean) isTransformPossible.invoke(null, bytes); + } + } From 8d14a792d4a20a89f942fa526f6969cac5191c86 Mon Sep 17 00:00:00 2001 From: Kyle Aure Date: Thu, 26 Oct 2023 15:09:57 -0500 Subject: [PATCH 3/3] Updates based on feedback --- .../internal/main/LibertyRuntimeTransformer.java | 2 +- .../com/ibm/example/bytecode/HelloWorldJava11.java | 12 ++++++++++++ .../com/ibm/example/bytecode/HelloWorldJava17.java | 12 ++++++++++++ .../com/ibm/example/bytecode/HelloWorldJava21.java | 12 ++++++++++++ .../com/ibm/example/bytecode/HelloWorldJava6.java | 12 ++++++++++++ .../com/ibm/example/bytecode/HelloWorldJava7.java | 12 ++++++++++++ .../example/bytecode/HelloWorldJava7StaticInit.java | 12 ++++++++++++ .../com/ibm/example/bytecode/HelloWorldJava8.java | 12 ++++++++++++ .../ibm/example/bytecode/HelloWorldJava8Lambdas.java | 12 ++++++++++++ .../example/bytecode/HelloWorldJava8StaticInit.java | 12 ++++++++++++ .../bytecode/HelloWorldJava8StaticLambdas.java | 12 ++++++++++++ .../test/com/ibm/example/bytecode/README.md | 5 ++--- .../test/com/ibm/ws/ras/RasTransformTest.java | 6 +++--- 13 files changed, 126 insertions(+), 7 deletions(-) diff --git a/dev/com.ibm.ws.ras.instrument/src/com/ibm/ws/ras/instrument/internal/main/LibertyRuntimeTransformer.java b/dev/com.ibm.ws.ras.instrument/src/com/ibm/ws/ras/instrument/internal/main/LibertyRuntimeTransformer.java index d67d9f14bad..474984d3c67 100644 --- a/dev/com.ibm.ws.ras.instrument/src/com/ibm/ws/ras/instrument/internal/main/LibertyRuntimeTransformer.java +++ b/dev/com.ibm.ws.ras.instrument/src/com/ibm/ws/ras/instrument/internal/main/LibertyRuntimeTransformer.java @@ -202,7 +202,7 @@ private static boolean isTransformPossible(byte[] bytes) { if (isJDK8WithHotReplaceBug) return classFileVersion <= Opcodes.V1_7; else - return classFileVersion <= Opcodes.V17; + return classFileVersion <= Opcodes.V22; } /** diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava11.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava11.java index 5563baa6e8e..dac111298ba 100644 --- a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava11.java +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava11.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ package com.ibm.example.bytecode; public class HelloWorldJava11 { diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava17.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava17.java index 608bf468ea2..a664e1c3c62 100644 --- a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava17.java +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava17.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ package com.ibm.example.bytecode; public class HelloWorldJava17 { diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava21.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava21.java index 37b5410fa2b..3edb22ea7b4 100644 --- a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava21.java +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava21.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ package com.ibm.example.bytecode; public class HelloWorldJava21 { diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava6.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava6.java index 1be09635c86..747bbbc9e59 100644 --- a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava6.java +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava6.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ package com.ibm.example.bytecode; public class HelloWorldJava6 { diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava7.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava7.java index 52bbb0f7a85..8f476fec8f9 100644 --- a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava7.java +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava7.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ package com.ibm.example.bytecode; public class HelloWorldJava7 { diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava7StaticInit.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava7StaticInit.java index b2845d1a583..ab0e2b3935d 100644 --- a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava7StaticInit.java +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava7StaticInit.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ package com.ibm.example.bytecode; public class HelloWorldJava7StaticInit { diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8.java index 007be0c9636..a6b1cca4bce 100644 --- a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8.java +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ package com.ibm.example.bytecode; public class HelloWorldJava8 { diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8Lambdas.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8Lambdas.java index 7fc5b0dfb5a..12a07ccaa65 100644 --- a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8Lambdas.java +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8Lambdas.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ package com.ibm.example.bytecode; import java.util.concurrent.Callable; diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8StaticInit.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8StaticInit.java index ffec5b27953..3689b3b9f76 100644 --- a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8StaticInit.java +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8StaticInit.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ package com.ibm.example.bytecode; public class HelloWorldJava8StaticInit { diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8StaticLambdas.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8StaticLambdas.java index 87c1b1148fe..d4ce6de69a7 100644 --- a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8StaticLambdas.java +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/HelloWorldJava8StaticLambdas.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2023 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ package com.ibm.example.bytecode; import java.util.concurrent.Callable; diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/README.md b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/README.md index a6d871d9767..fa6c8900cb7 100644 --- a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/README.md +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/example/bytecode/README.md @@ -1,8 +1,7 @@ ## Source files -The classes compiled in this package are not meant to be used for testing. -Instead, they are placeholder .java files that we need to manually compile at different java levels. -The compiled classes will then be put into the `test data` directory. +The classes in this directory are the source files for the .class files located in the `test data` directory. +If you are adding a new class to this directory you need to manually compile it at the java level it was written to be tested against. ### Generate new class files diff --git a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/ws/ras/RasTransformTest.java b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/ws/ras/RasTransformTest.java index 9a233e7fd24..232108096e6 100644 --- a/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/ws/ras/RasTransformTest.java +++ b/dev/com.ibm.ws.ras.instrument_test/test/com/ibm/ws/ras/RasTransformTest.java @@ -39,6 +39,7 @@ import com.ibm.ws.ras.instrument.internal.main.LibertyRuntimeTransformer; +//TODO add tests that make sure classes are instrumented with trace. @SuppressWarnings("deprecation") public class RasTransformTest extends LibertyRuntimeTransformer { @@ -71,7 +72,7 @@ public static void setup() { majorCodeMap.put("19", 63); majorCodeMap.put("20", 64); majorCodeMap.put("21", 65); - majorCodeMap.put("22", 65); + majorCodeMap.put("22", 66); } /** @@ -388,9 +389,8 @@ public void testJava17Basic() { } - //FIXME - This test is currently failing because isTransformPossible returns false //TODO expand this test to actually test Java 21 features https://openjdk.org/jeps/441 - //@Test + @Test public void testJava21Basic() { assumeTrue(Integer.parseInt(System.getProperty("java.specification.version")) >= 21); String classPath = "test/test data/com/ibm/example/bytecode/HelloWorldJava21.class";