From 7d47cba01043c93bab95b59e66b727580351e85f Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Wed, 28 Feb 2018 11:53:14 -0800 Subject: Bug#531694: generate more optional thisJoinPoint construction code This commit introduces some new methods into the runtime Factory class and modifies code generation to use them (and to use the form of the LDC bytecode that loads class constants). --- .../systemtest/ajc151/NewarrayJoinpointTests.java | 18 ++- .../systemtest/ajc190/AllTestsAspectJ190.java | 2 +- .../systemtest/ajc190/EfficientTJPTests.java | 126 +++++++++++++++ .../org/aspectj/systemtest/ajc190/features190.xml | 172 +++++++++++++++++++++ 4 files changed, 313 insertions(+), 5 deletions(-) create mode 100644 tests/src/org/aspectj/systemtest/ajc190/EfficientTJPTests.java create mode 100644 tests/src/org/aspectj/systemtest/ajc190/features190.xml (limited to 'tests/src') diff --git a/tests/src/org/aspectj/systemtest/ajc151/NewarrayJoinpointTests.java b/tests/src/org/aspectj/systemtest/ajc151/NewarrayJoinpointTests.java index 9c92f8488..9654c04dd 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/NewarrayJoinpointTests.java +++ b/tests/src/org/aspectj/systemtest/ajc151/NewarrayJoinpointTests.java @@ -13,13 +13,13 @@ package org.aspectj.systemtest.ajc151; import java.io.File; import java.util.List; -import junit.framework.Test; - import org.aspectj.asm.AsmManager; import org.aspectj.asm.IProgramElement; import org.aspectj.asm.IRelationship; import org.aspectj.testing.XMLBasedAjcTestCase; +import junit.framework.Test; + /* * The design: * @@ -59,6 +59,15 @@ public class NewarrayJoinpointTests extends XMLBasedAjcTestCase { runTest("thisjoinpoint"); } + public void testThisJoinPoint19() { + try { + System.setProperty("ASPECTJ_OPTS", "-Xajruntimetarget:1.9"); + runTest("thisjoinpoint"); + } finally { + System.setProperty("ASPECTJ_OPTS", ""); + } + } + public void testDifferentAdviceKinds() { runTest("different advice kinds"); } @@ -105,9 +114,9 @@ public class NewarrayJoinpointTests extends XMLBasedAjcTestCase { assertTrue("Couldnt find 'Five' type in the model", ipe != null); List kids = ipe.getChildren(); assertTrue("Couldn't find 'main' method in the 'Five' type", kids != null && kids.size() == 1); - List codenodes = ((IProgramElement) kids.get(0)).getChildren(); + List codenodes = kids.get(0).getChildren(); assertTrue("Couldn't find nodes below 'main' method", codenodes != null && codenodes.size() == 1); - IProgramElement arrayCtorCallNode = (IProgramElement) codenodes.get(0); + IProgramElement arrayCtorCallNode = codenodes.get(0); String exp = "constructor-call(void java.lang.Integer[].(int))"; assertTrue("Expected '" + exp + "' but found " + arrayCtorCallNode.toString(), arrayCtorCallNode.toString().equals(exp)); List rels = AsmManager.lastActiveStructureModel.getRelationshipMap().get(arrayCtorCallNode); @@ -119,6 +128,7 @@ public class NewarrayJoinpointTests extends XMLBasedAjcTestCase { return XMLBasedAjcTestCase.loadSuite(NewarrayJoinpointTests.class); } + @Override protected File getSpecFile() { return getClassResource("newarray_joinpoint.xml"); } diff --git a/tests/src/org/aspectj/systemtest/ajc190/AllTestsAspectJ190.java b/tests/src/org/aspectj/systemtest/ajc190/AllTestsAspectJ190.java index 2ebc12e7c..d0f7734f3 100644 --- a/tests/src/org/aspectj/systemtest/ajc190/AllTestsAspectJ190.java +++ b/tests/src/org/aspectj/systemtest/ajc190/AllTestsAspectJ190.java @@ -20,7 +20,7 @@ public class AllTestsAspectJ190 { // $JUnit-BEGIN$ suite.addTest(Ajc190Tests.suite()); suite.addTest(SanityTests19.suite()); -// suite.addTest(EfficientTJPTests.suite()); + suite.addTest(EfficientTJPTests.suite()); suite.addTest(ModuleTests.suite()); suite.addTest(Annotations.suite()); // $JUnit-END$ diff --git a/tests/src/org/aspectj/systemtest/ajc190/EfficientTJPTests.java b/tests/src/org/aspectj/systemtest/ajc190/EfficientTJPTests.java new file mode 100644 index 000000000..3564f9469 --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc190/EfficientTJPTests.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2018 Contributors + * 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 + *******************************************************************************/ +package org.aspectj.systemtest.ajc190; + +import java.io.File; + +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.testing.XMLBasedAjcTestCase; + +import junit.framework.Assert; +import junit.framework.Test; + +/** + * + * @author Andy Clement + */ +public class EfficientTJPTests extends XMLBasedAjcTestCase { + + public void testThisJoinPointMethodExecution() { + // Test setting it via sys props rather than passing the option directly + try { + System.setProperty("ASPECTJ_OPTS", "-Xajruntimetarget:1.9"); + runTest("tjp 1"); + checkPreClinitContains("One","Factory.makeMethodSJP"); + } finally { + System.setProperty("ASPECTJ_OPTS", ""); + } + } + + public void testThisEnclosingJoinPointMethodExecution() { + runTest("tjp 2"); + checkPreClinitContains("Two","Factory.makeMethodESJP"); + } + + public void testThisJoinPointConstructorExecution() { + runTest("tjp 3"); + checkPreClinitContains("Three","Factory.makeConstructorSJP"); + } + + public void testThisEnclosingJoinPointConstructorExecution() { + runTest("tjp 3a"); + checkPreClinitContains("ThreeA","Factory.makeConstructorESJP"); + } + + public void testThisJoinPointHandler() { + runTest("tjp 4"); + checkPreClinitContains("Four","Factory.makeCatchClauseSJP"); + } + + public void testThisEnclosingJoinPointHandler() { + runTest("tjp 4a"); + checkPreClinitContains("FourA","Factory.makeMethodESJP"); + } + + public void testThisJoinPointFieldGet() { + runTest("tjp get fields"); + checkPreClinitContains("Fields","Factory.makeFieldSJP"); + } + + public void testThisEnclosingJoinPointFieldGet() { + runTest("tjp get fieldsE"); + checkPreClinitContains("FieldsE","Factory.makeMethodESJP"); + } + + public void testThisJoinPointFieldSet() { + runTest("tjp set fields"); + checkPreClinitContains("Fields2","Factory.makeFieldSJP"); + } + + public void testThisJoinPointClinit() { + runTest("tjp clinit"); + checkPreClinitContains("Clinit","Factory.makeInitializerSJP"); + } + + public void testThisEnclosingJoinPointClinit() { + runTest("tejp clinit"); + checkPreClinitContains("ClinitE","Factory.makeInitializerESJP"); + } + + public void testThisJoinPointAdvice() { + // covers enclosing joinpoint too + runTest("tjp advice"); + checkPreClinitContains("X","Factory.makeAdviceESJP"); + } + + public void testThisJoinPointInitialization() { + runTest("tjp init"); + checkPreClinitContains("A","Factory.makeConstructorESJP"); + checkPreClinitContains("B","Factory.makeConstructorESJP"); + } + + // /////////////////////////////////////// + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(EfficientTJPTests.class); + } + + @Override + protected File getSpecFile() { + return getClassResource("features190.xml"); + } + + public void checkPreClinitContains(String classname, String text) { + try { + JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), classname); + Method[] meths = jc.getMethods(); + for (int i = 0; i < meths.length; i++) { + Method method = meths[i]; + if (method.getName().equals("ajc$preClinit")) { + String code = method.getCode().getCodeString(); + assertTrue("Expected to contain '"+text+"':\n"+code,code.contains(text)); + return; + } + } + Assert.fail("Unable to find ajc$preClinit in class "+classname); + } catch (Exception e) { + Assert.fail(e.toString()); + } + } + +} diff --git a/tests/src/org/aspectj/systemtest/ajc190/features190.xml b/tests/src/org/aspectj/systemtest/ajc190/features190.xml new file mode 100644 index 000000000..1fb931e97 --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc190/features190.xml @@ -0,0 +1,172 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3