From f3ff0752b8ee68583fb5a90687ddb5943c2df25b Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Sat, 10 Apr 2021 12:32:04 +0700 Subject: Remove JRockit LTW support, particularly JRockitAgent In two places, the documentation now contains this text: "Since AspectJ 1.9.7, the obsolete Oracle/BEA JRockit agent is no longer part of AspectJ. JRockit JDK never supported Java versions higher than 1.6. Several JRockit JVM features are now part of HotSpot and tools like Mission Control available for OpenJDK and Oracle JDK." The decision to drop JRockit support was made during a discussion between Alexander Kriegisch and Andy Clement: Andy Clement wrote on 26 Mar 2021: > Yes I think so. > > > Alexander Kriegisch wrote on 26 Mar 2021: > >> https://en.wikipedia.org/wiki/JRockit >> >> Can we get rid of that? AspectJ requires Java 8, JRockit never >> supported more than Java 6. Signed-off-by: Alexander Kriegisch --- loadtime/pom.xml | 8 - .../org/aspectj/weaver/loadtime/JRockitAgent.java | 84 -------- .../java/org/aspectj/bea/jvm/ClassLibraryImpl.java | 29 --- .../src/test/java/org/aspectj/bea/jvm/JVMImpl.java | 24 --- .../org/aspectj/loadtime/LoadtimeModuleTests.java | 2 - .../aspectj/weaver/loadtime/JRockitAgentTest.java | 228 --------------------- 6 files changed, 375 deletions(-) delete mode 100644 loadtime/src/main/java/org/aspectj/weaver/loadtime/JRockitAgent.java delete mode 100644 loadtime/src/test/java/org/aspectj/bea/jvm/ClassLibraryImpl.java delete mode 100644 loadtime/src/test/java/org/aspectj/bea/jvm/JVMImpl.java delete mode 100644 loadtime/src/test/java/org/aspectj/weaver/loadtime/JRockitAgentTest.java (limited to 'loadtime') diff --git a/loadtime/pom.xml b/loadtime/pom.xml index d7333cd72..7c03455e5 100644 --- a/loadtime/pom.xml +++ b/loadtime/pom.xml @@ -66,14 +66,6 @@ xercesImpl ${lib.ant.xerces.version} - - jrockit - jrockit - 1.0 - system - ${project.basedir}/../lib/jrockit/jrockit.jar - - ant diff --git a/loadtime/src/main/java/org/aspectj/weaver/loadtime/JRockitAgent.java b/loadtime/src/main/java/org/aspectj/weaver/loadtime/JRockitAgent.java deleted file mode 100644 index 56ad0e958..000000000 --- a/loadtime/src/main/java/org/aspectj/weaver/loadtime/JRockitAgent.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Webster - initial implementation - *******************************************************************************/ -package org.aspectj.weaver.loadtime; - -import java.util.Stack; - -import com.bea.jvm.ClassLibrary; -import com.bea.jvm.JVMFactory; - -/** - * BEA JRocket JMAPI agent. - * - * Use "-Xmanagement:class=org.aspectj.weaver.loadtime.JRockitAgent" - */ -public class JRockitAgent implements com.bea.jvm.ClassPreProcessor { - - private ClassPreProcessor preProcessor; - - /* - * This is used to implement the recursion protection offered by JVMTI but not by JRockit JMAPI. I we are called to preProcess a - * class while already preProcessing another we will return immediately - */ - private static ThreadLocalStack stack = new ThreadLocalStack(); - - public JRockitAgent() { - this.preProcessor = new Aj(); - - ClassLibrary cl = JVMFactory.getJVM().getClassLibrary(); - cl.setClassPreProcessor(this); - } - - public byte[] preProcess(ClassLoader loader, String className, byte[] bytes) { - byte[] newBytes = bytes; - - if (stack.empty()) { - stack.push(className); - newBytes = preProcessor.preProcess(className, bytes, loader, null); - stack.pop(); - } - - return newBytes; - } - - private static class ThreadLocalStack extends ThreadLocal { - - public boolean empty() { - Stack stack = (Stack) get(); - return stack.empty(); - } - - public Object peek() { - Object obj = null; - Stack stack = (Stack) get(); - if (!stack.empty()) - obj = stack.peek(); - return obj; - } - - public void push(Object obj) { - Stack stack = (Stack) get(); - if (!stack.empty() && obj == stack.peek()) - throw new RuntimeException(obj.toString()); - stack.push(obj); - } - - public Object pop() { - Stack stack = (Stack) get(); - return stack.pop(); - } - - protected Object initialValue() { - return new Stack(); - } - } - -} diff --git a/loadtime/src/test/java/org/aspectj/bea/jvm/ClassLibraryImpl.java b/loadtime/src/test/java/org/aspectj/bea/jvm/ClassLibraryImpl.java deleted file mode 100644 index 8b4c58446..000000000 --- a/loadtime/src/test/java/org/aspectj/bea/jvm/ClassLibraryImpl.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Webster - initial implementation - *******************************************************************************/ -package org.aspectj.bea.jvm; - -import com.bea.jvm.ClassLibrary; -import com.bea.jvm.ClassPreProcessor; -import com.bea.jvm.NotAvailableException; - -public class ClassLibraryImpl implements ClassLibrary { - - private ClassPreProcessor preProcessor; - - public ClassPreProcessor getClassPreProcessor() throws NotAvailableException { - return preProcessor; - } - - public void setClassPreProcessor(ClassPreProcessor classPreProcessor) { - this.preProcessor = classPreProcessor; - } - -} diff --git a/loadtime/src/test/java/org/aspectj/bea/jvm/JVMImpl.java b/loadtime/src/test/java/org/aspectj/bea/jvm/JVMImpl.java deleted file mode 100644 index caae32e6f..000000000 --- a/loadtime/src/test/java/org/aspectj/bea/jvm/JVMImpl.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Webster - initial implementation - *******************************************************************************/ -package org.aspectj.bea.jvm; - -import com.bea.jvm.ClassLibrary; -import com.bea.jvm.JVM; - -public class JVMImpl implements JVM { - - private ClassLibrary libarary = new ClassLibraryImpl(); - - public ClassLibrary getClassLibrary() { - return libarary; - } - -} diff --git a/loadtime/src/test/java/org/aspectj/loadtime/LoadtimeModuleTests.java b/loadtime/src/test/java/org/aspectj/loadtime/LoadtimeModuleTests.java index 9d365ffab..352156f82 100644 --- a/loadtime/src/test/java/org/aspectj/loadtime/LoadtimeModuleTests.java +++ b/loadtime/src/test/java/org/aspectj/loadtime/LoadtimeModuleTests.java @@ -10,7 +10,6 @@ package org.aspectj.loadtime; import org.aspectj.weaver.loadtime.AjTest; import org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptorTest; -import org.aspectj.weaver.loadtime.JRockitAgentTest; import org.aspectj.weaver.loadtime.LoadtimeTest; import org.aspectj.weaver.loadtime.WeavingContextTest; import org.aspectj.weaver.loadtime.WeavingURLClassLoaderTest; @@ -32,7 +31,6 @@ public class LoadtimeModuleTests extends TestCase { suite.addTestSuite(DocumentParserTest.class); suite.addTestSuite(AjTest.class); suite.addTestSuite(ClassLoaderWeavingAdaptorTest.class); - suite.addTestSuite(JRockitAgentTest.class); suite.addTestSuite(LoadtimeTest.class); suite.addTestSuite(WeavingContextTest.class); suite.addTestSuite(WeavingURLClassLoaderTest.class); diff --git a/loadtime/src/test/java/org/aspectj/weaver/loadtime/JRockitAgentTest.java b/loadtime/src/test/java/org/aspectj/weaver/loadtime/JRockitAgentTest.java deleted file mode 100644 index 7f9d235d0..000000000 --- a/loadtime/src/test/java/org/aspectj/weaver/loadtime/JRockitAgentTest.java +++ /dev/null @@ -1,228 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Webster - initial implementation - *******************************************************************************/ -package org.aspectj.weaver.loadtime; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.jar.JarFile; -import java.util.zip.ZipEntry; - -import org.aspectj.util.FileUtil; -import org.aspectj.util.LangUtil; - -import com.bea.jvm.ClassPreProcessor; -import com.bea.jvm.JVMFactory; - -import junit.framework.TestCase; - -public class JRockitAgentTest extends TestCase { - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - public void testJRockitAgent() { - ClassPreProcessor preProcessor = new JRockitAgent(); - ClassPreProcessor expectedPreProcessor = JVMFactory.getJVM().getClassLibrary().getClassPreProcessor(); - assertEquals("JRocketAgent must be registered", expectedPreProcessor, preProcessor); - } - - public void testPreProcess() { - ClassPreProcessor preProcessor = new JRockitAgent(); - preProcessor.preProcess(null, "foo.Bar", new byte[] {}); - } - - public void testJrockitRecursionProtection() { - URL jrockit = FileUtil.getFileURL(new File("../lib/jrockit/jrockit.jar")); - URL[] urls = new URL[] {jrockit}; - URLClassLoader thisLoader = new URLClassLoader(urls, getClass().getClassLoader()); - try { - ClassLoader loader = new JRockitClassLoader(thisLoader); - Class.forName("java.lang.Object", false, loader); - Class.forName("junit.framework.TestCase", false, loader); - } catch (Exception ex) { - ex.printStackTrace(); - fail(ex.toString()); - } - } - - private class JRockitClassLoader extends ClassLoader { - - public final static boolean debug = false; - - private List path = new LinkedList(); - // private com.bea.jvm.ClassPreProcessor agent; - private Object agent; - private Method preProcess; - - public JRockitClassLoader(URLClassLoader clone) throws Exception { - /* Use extensions loader */ - super(clone.getParent()); - - URL[] urls = clone.getURLs(); - for (URL value : urls) { - Object pathElement; - URL url = value; - if (debug) - System.out.println("JRockitClassLoader.JRockitClassLoader() url=" + url.getPath()); - File file = new File(encode(url.getFile())); - if (debug) - System.out.println("JRockitClassLoader.JRockitClassLoader() file" + file); - if (file.isDirectory()) - pathElement = file; - else if (file.exists() && file.getName().endsWith(".jar")) - pathElement = new JarFile(file); - else - throw new RuntimeException(file.getAbsolutePath()); - path.add(pathElement); - } - - Class agentClazz = Class.forName("org.aspectj.weaver.loadtime.JRockitAgent", false, this); - Object obj = agentClazz.getDeclaredConstructor().newInstance(); - if (debug) - System.out.println("JRockitClassLoader.JRockitClassLoader() obj=" + obj); - this.agent = obj; - byte[] bytes = new byte[] {}; - Class[] parameterTypes = new Class[] { java.lang.ClassLoader.class, java.lang.String.class, bytes.getClass() }; - preProcess = agentClazz.getMethod("preProcess", parameterTypes); - } - - /* Get rid of escaped characters */ - private String encode(String s) { - StringBuffer result = new StringBuffer(); - int i = s.indexOf("%"); - while (i != -1) { - result.append(s.substring(0, i)); - String escaped = s.substring(i + 1, i + 3); - s = s.substring(i + 3); - Integer value = Integer.valueOf(escaped, 16); - result.append(Character.valueOf((char) value.intValue())); - i = s.indexOf("%"); - } - result.append(s); - return result.toString(); - } - - protected Class findClass(String name) throws ClassNotFoundException { - if (debug) - System.out.println("> JRockitClassLoader.findClass() name=" + name); - Class clazz = null; - try { - clazz = super.findClass(name); - } catch (ClassNotFoundException ex) { - for (Iterator i = path.iterator(); clazz == null && i.hasNext();) { - byte[] classBytes = null; - try { - Object pathElement = i.next(); - if (pathElement instanceof File) { - File dir = (File) pathElement; - String className = name.replace('.', '/') + ".class"; - File classFile = new File(dir, className); - if (classFile.exists()) - classBytes = loadClassFromFile(name, classFile); - } else { - JarFile jar = (JarFile) pathElement; - String className = name.replace('.', '/') + ".class"; - ZipEntry entry = jar.getEntry(className); - if (entry != null) - classBytes = loadBytesFromZipEntry(jar, entry); - } - - if (classBytes != null) { - clazz = defineClass(name, classBytes); - } - } catch (IOException ioException) { - ex.printStackTrace(); - } - } - } - - if (debug) - System.out.println("< JRockitClassLoader.findClass() name=" + name); - return clazz; - } - - private Class defineClass(String name, byte[] bytes) { - if (debug) - System.out.println("> JRockitClassLoader.defineClass() name=" + name); - try { - if (agent != null) - preProcess.invoke(agent, new Object[] { this, name, bytes }); - } catch (IllegalAccessException iae) { - iae.printStackTrace(); - throw new ClassFormatError(iae.getMessage()); - } catch (InvocationTargetException ite) { - ite.printStackTrace(); - throw new ClassFormatError(ite.getTargetException().getMessage()); - } - if (debug) - System.out.println("< JRockitClassLoader.defineClass() name=" + name); - return super.defineClass(name, bytes, 0, bytes.length); - } - - private byte[] loadClassFromFile(String name, File file) throws IOException { - if (debug) - System.out.println("JRockitClassLoader.loadClassFromFile() file=" + file); - - byte[] bytes; - bytes = new byte[(int) file.length()]; - FileInputStream fis = null; - try { - fis = new FileInputStream(file); - bytes = readBytes(fis, bytes); - } finally { - if (fis != null) - fis.close(); - } - - return bytes; - } - - private byte[] loadBytesFromZipEntry(JarFile jar, ZipEntry entry) throws IOException { - if (debug) - System.out.println("JRockitClassLoader.loadBytesFromZipEntry() entry=" + entry); - - byte[] bytes; - bytes = new byte[(int) entry.getSize()]; - InputStream is = null; - try { - is = jar.getInputStream(entry); - bytes = readBytes(is, bytes); - } finally { - if (is != null) - is.close(); - } - - return bytes; - } - - private byte[] readBytes(InputStream is, byte[] bytes) throws IOException { - for (int offset = 0; offset < bytes.length;) { - int read = is.read(bytes, offset, bytes.length - offset); - offset += read; - } - return bytes; - } - } -} -- cgit v1.2.3