Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2018-02-13 16:16:52 +0000
committerStephan Herrmann2018-02-13 16:24:45 +0000
commitde2380fcb6b5c1c9316a8f765d484ec028fb713e (patch)
treed776f64746fff41bab962568e7d0e905be9e6905
parentd7490ab9200859ac8c944ed8e5c7e2343b0aca0b (diff)
downloadorg.eclipse.objectteams-de2380fcb6b5c1c9316a8f765d484ec028fb713e.tar.gz
org.eclipse.objectteams-de2380fcb6b5c1c9316a8f765d484ec028fb713e.tar.xz
org.eclipse.objectteams-de2380fcb6b5c1c9316a8f765d484ec028fb713e.zip
Backport Bug 530914 - [otdre] Wrong kind of super-call in callOrig where
super is in fact not woven. - improved fix, some use cases should considers supers, others not cherry-pick of commit b8025c2d5fb0838569199018c4bfca4469989ddf
-rw-r--r--plugins/org.eclipse.objectteams.otequinox/src/org/eclipse/objectteams/internal/osgi/weaving/DelegatingTransformer.java6
-rw-r--r--plugins/org.eclipse.objectteams.otequinox/src/org/eclipse/objectteams/internal/osgi/weaving/OTWeavingHook.java6
-rw-r--r--plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/AbstractBoundClass.java30
-rw-r--r--plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AsmWritableBoundClass.java21
-rw-r--r--plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/MoveCodeToCallOrigAdapter.java2
-rw-r--r--plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/transformer/IWeavingContext.java16
-rw-r--r--plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/transformer/jplis/ObjectTeamsTransformer.java8
7 files changed, 57 insertions, 32 deletions
diff --git a/plugins/org.eclipse.objectteams.otequinox/src/org/eclipse/objectteams/internal/osgi/weaving/DelegatingTransformer.java b/plugins/org.eclipse.objectteams.otequinox/src/org/eclipse/objectteams/internal/osgi/weaving/DelegatingTransformer.java
index 10b6c97f9..68f199480 100644
--- a/plugins/org.eclipse.objectteams.otequinox/src/org/eclipse/objectteams/internal/osgi/weaving/DelegatingTransformer.java
+++ b/plugins/org.eclipse.objectteams.otequinox/src/org/eclipse/objectteams/internal/osgi/weaving/DelegatingTransformer.java
@@ -146,7 +146,11 @@ public abstract class DelegatingTransformer {
return new IWeavingContext() {
@Override
public boolean isWeavable(String className) {
- return className != null && hook.requiresWeaving(bundleWiring, className, null) != WeavingReason.None;
+ return isWeavable(className, false);
+ }
+ @Override
+ public boolean isWeavable(String className, boolean considerSupers) {
+ return className != null && hook.requiresWeaving(bundleWiring, className, null, considerSupers) != WeavingReason.None;
}
@Override
diff --git a/plugins/org.eclipse.objectteams.otequinox/src/org/eclipse/objectteams/internal/osgi/weaving/OTWeavingHook.java b/plugins/org.eclipse.objectteams.otequinox/src/org/eclipse/objectteams/internal/osgi/weaving/OTWeavingHook.java
index 229f271a7..a952a2db5 100644
--- a/plugins/org.eclipse.objectteams.otequinox/src/org/eclipse/objectteams/internal/osgi/weaving/OTWeavingHook.java
+++ b/plugins/org.eclipse.objectteams.otequinox/src/org/eclipse/objectteams/internal/osgi/weaving/OTWeavingHook.java
@@ -265,7 +265,7 @@ public class OTWeavingHook implements WeavingHook, WovenClassListener {
}
byte[] bytes = wovenClass.getBytes();
- WeavingReason reason = requiresWeaving(bundleWiring, className, bytes);
+ WeavingReason reason = requiresWeaving(bundleWiring, className, bytes, true);
if (reason != WeavingReason.None) {
// do whatever is needed *before* loading this class:
boolean allAspectsAreDenied = triggerBaseTripWires(bundleName, wovenClass);
@@ -335,7 +335,7 @@ public class OTWeavingHook implements WeavingHook, WovenClassListener {
return false;
}
- WeavingReason requiresWeaving(BundleWiring bundleWiring, @NonNull String className, byte[] bytes) {
+ WeavingReason requiresWeaving(BundleWiring bundleWiring, @NonNull String className, byte[] bytes, boolean considerSupers) {
// 1. consult the aspect binding registry (for per-bundle info):
@SuppressWarnings("null")@NonNull // FIXME: org.eclipse.osgi.internal.resolver.BundleDescriptionImpl.getBundle() can return null!
@@ -356,7 +356,7 @@ public class OTWeavingHook implements WeavingHook, WovenClassListener {
return WeavingReason.Base; // we may be first, go ahead and trigger the trip wire
}
}
- if (isAdaptedBaseClass(aspectBindings, className, bytes != null, bytes, bundleWiring.getClassLoader()))
+ if (isAdaptedBaseClass(aspectBindings, className, considerSupers, bytes, bundleWiring.getClassLoader()))
return WeavingReason.Base;
}
diff --git a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/AbstractBoundClass.java b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/AbstractBoundClass.java
index fd84a999d..7349238d9 100644
--- a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/AbstractBoundClass.java
+++ b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/AbstractBoundClass.java
@@ -463,14 +463,14 @@ public abstract class AbstractBoundClass implements IBoundClass {
* It parses the bytecode, if that has not already been done
* @return
*/
- public String getInternalWeavableSuperClassName() {
- if (!isSuperWeavable())
+ public String getInternalWeavableSuperClassName(boolean considerSupers) {
+ if (!isSuperWeavable(considerSupers))
return null;
parseBytecode();
return internalSuperClassName;
}
- protected abstract boolean isSuperWeavable();
+ protected abstract boolean isSuperWeavable(boolean considerSupers);
/**
* Returns the internal name of this class
@@ -726,7 +726,7 @@ public abstract class AbstractBoundClass implements IBoundClass {
if (method.isImplemented()) {
// So redefine the method
weaveBindingInImplementedMethod(task);
- if (!method.isStatic() && weavingContext.isWeavable(getSuperClassName())) {
+ if (!method.isStatic() && weavingContext.isWeavable(getSuperClassName(), false)) {
AbstractBoundClass superclass = getSuperclass();
Method superMethod = superclass.getMethod(method.getName(), method.getSignature(), true, false);
if (superMethod.isImplemented()) {
@@ -735,16 +735,20 @@ public abstract class AbstractBoundClass implements IBoundClass {
}
}
} else {
- //No, so weave this class and delegate to the super class
+ // No, so weave this class and delegate to the implementing super class
weaveBindingInNotImplementedMethod(task);
- if (weavingContext.isWeavable(getSuperClassName())) {
- AbstractBoundClass superclass = getSuperclass();
- Method superMethod = superclass.getMethod(method, task);
- if (superMethod != null) {
- WeavingTask newTask = new WeavingTask(WeavingTaskType.WEAVE_BINDING_OF_SUBCLASS, superMethod, task, null);
- superclass.addWeavingTask(newTask, true/*standBy*/);
- affectedClasses.add(superclass);
+ AbstractBoundClass superclass = getSuperclass();
+ while (superclass != null && !superclass.isJavaLangObject()) {
+ if (weavingContext.isWeavable(superclass.getName(), false)) { // explicitly traversing supers
+ Method superMethod = superclass.getMethod(method, task);
+ if (superMethod != null) {
+ WeavingTask newTask = new WeavingTask(WeavingTaskType.WEAVE_BINDING_OF_SUBCLASS, superMethod, task, null);
+ superclass.addWeavingTask(newTask, true/*standBy*/);
+ affectedClasses.add(superclass);
+ break;
+ }
}
+ superclass = superclass.getSuperclass();
}
}
@@ -1115,7 +1119,7 @@ public abstract class AbstractBoundClass implements IBoundClass {
}
Method superMethod = superClass.getMethod(task);
if (superMethod.isImplemented()) {
- isWeavable = weavingContext.isWeavable(superClass.getName());
+ isWeavable = weavingContext.isWeavable(superClass.getName(), false); // explicitly traversing supers
break;
}
superClass = superClass.getSuperclass();
diff --git a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AsmWritableBoundClass.java b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AsmWritableBoundClass.java
index e10148e19..5b69f47db 100644
--- a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AsmWritableBoundClass.java
+++ b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AsmWritableBoundClass.java
@@ -394,21 +394,19 @@ class AsmWritableBoundClass extends AsmBoundClass {
if (isInterface())
methodModifiers |= Opcodes.ACC_ABSTRACT;
- if (!isInterface() && !isSuperWeavable())
+ if (!isInterface() && !isSuperWeavable(true))
addField(ConstantMembers.roleSet, Opcodes.ACC_PUBLIC);
- String internalWeavableSuperClassName = getInternalWeavableSuperClassName();
-
- addEmptyMethod(ConstantMembers.callOrig, methodModifiers, null, null, internalWeavableSuperClassName);
- addEmptyMethod(ConstantMembers.callAllBindingsClient, methodModifiers, null, null, internalWeavableSuperClassName);
+ addEmptyMethod(ConstantMembers.callOrig, methodModifiers, null, null, getInternalWeavableSuperClassName(false));
+ addEmptyMethod(ConstantMembers.callAllBindingsClient, methodModifiers, null, null, getInternalWeavableSuperClassName(false));
// the methods callOrigStatic and accessStatic have to already exist to call it in a concrete team
if (!isInterface()) {
addEmptyMethod(getCallOrigStatic(), Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, null, null, null);
addEmptyMethod(ConstantMembers.accessStatic, Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, null, null, null);
}
- addEmptyMethod(ConstantMembers.access, methodModifiers, null, null, internalWeavableSuperClassName);
- addEmptyMethod(ConstantMembers.addOrRemoveRole, methodModifiers, null, null, internalWeavableSuperClassName);
+ addEmptyMethod(ConstantMembers.access, methodModifiers, null, null, getInternalWeavableSuperClassName(true));
+ addEmptyMethod(ConstantMembers.addOrRemoveRole, methodModifiers, null, null, getInternalWeavableSuperClassName(true));
if (!isInterface())
multiAdapter.addVisitor(new AddAfterClassLoadingHook(this.writer, this));
@@ -452,7 +450,7 @@ class AsmWritableBoundClass extends AsmBoundClass {
@Override
protected void prepareForFirstTransformation() {
if (!isTransformed && !isInterface()) {
- nodes.add(new CreateSwitchAdapter(ConstantMembers.callOrig, getInternalWeavableSuperClassName()));
+ nodes.add(new CreateSwitchAdapter(ConstantMembers.callOrig, getInternalWeavableSuperClassName(false)));
nodes.add(new CreateSwitchForCallAllBindingsNode());
nodes.add(new CreateAddRemoveRoleMethod());
isTransformed = true;
@@ -478,7 +476,7 @@ class AsmWritableBoundClass extends AsmBoundClass {
@Override
protected void prepareForFirstMemberAccess() {
if (!isTransformedForMemberAccess && !isInterface()) {
- String internalWeavableSuperClassName = getInternalWeavableSuperClassName();
+ String internalWeavableSuperClassName = getInternalWeavableSuperClassName(true);
nodes.add(new CreateSwitchForAccessAdapter(ConstantMembers.access, internalWeavableSuperClassName, this));
nodes.add(new CreateSwitchForAccessAdapter(ConstantMembers.accessStatic, internalWeavableSuperClassName, this));
isTransformedForMemberAccess = true;
@@ -494,9 +492,10 @@ class AsmWritableBoundClass extends AsmBoundClass {
return isFirstTransformation;
}
- protected boolean isSuperWeavable() {
+ @Override
+ protected boolean isSuperWeavable(boolean considerSupers) {
if (this.superIsWeavable == null)
- this.superIsWeavable = weavingContext.isWeavable(getSuperClassName());
+ this.superIsWeavable = weavingContext.isWeavable(getSuperClassName(), considerSupers);
return this.superIsWeavable;
}
}
diff --git a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/MoveCodeToCallOrigAdapter.java b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/MoveCodeToCallOrigAdapter.java
index 9be258a4b..2593b47ac 100644
--- a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/MoveCodeToCallOrigAdapter.java
+++ b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/MoveCodeToCallOrigAdapter.java
@@ -70,7 +70,7 @@ public class MoveCodeToCallOrigAdapter extends AbstractTransformableClassNode {
callOrig = ConstantMembers.callOrig;
}
if (weavingContext != null)
- superIsWeavable = weavingContext.isWeavable(clazz.getSuperClassName());
+ superIsWeavable = weavingContext.isWeavable(clazz.getSuperClassName(), false);
if (superIsWeavable)
superclass = clazz.getSuperclass();
this.baseSuperRequired = baseSuperRequired;
diff --git a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/transformer/IWeavingContext.java b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/transformer/IWeavingContext.java
index 48e2c5f1a..5bb24214f 100644
--- a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/transformer/IWeavingContext.java
+++ b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/transformer/IWeavingContext.java
@@ -1,7 +1,7 @@
/**********************************************************************
* This file is part of "Object Teams Dynamic Runtime Environment"
*
- * Copyright 2015 GK Software AG
+ * Copyright 2015, 2018 GK Software AG
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -29,8 +29,22 @@ public interface IWeavingContext {
* @param className full qualified classname, dot-separated for packages
* and dollar-separated for nested classes.
* @return true if the given class is included in load-time weaving.
+ * @deprecated please use {@link #isWeavable(String, boolean)}.
*/
+ @Deprecated
boolean isWeavable(String className);
+
+ /**
+ * Is the given class included in load-time weaving, i.e., will
+ * the weaving context pass the class to the transformer during
+ * initial loading?
+ * @param className full qualified classname, dot-separated for packages
+ * and dollar-separated for nested classes.
+ * @param considerSupers controls whether super classes should be searched, too.
+ * @return true if the given class is included in load-time weaving.
+ * @since 1.3.2
+ */
+ boolean isWeavable(String className, boolean considerSupers);
/**
* When reweaving for className is required, check if this needs to
diff --git a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/transformer/jplis/ObjectTeamsTransformer.java b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/transformer/jplis/ObjectTeamsTransformer.java
index 3102e8656..4abf91b6d 100644
--- a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/transformer/jplis/ObjectTeamsTransformer.java
+++ b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/transformer/jplis/ObjectTeamsTransformer.java
@@ -44,7 +44,11 @@ public class ObjectTeamsTransformer implements ClassFileTransformer {
public ObjectTeamsTransformer() {
this.weavingContext = new IWeavingContext() {
- @Override public boolean isWeavable(String className) {
+ @Override
+ public boolean isWeavable(String className) {
+ return isWeavable(className, false); // considerSupers is ignored by us, FIXME: why that?
+ }
+ @Override public boolean isWeavable(String className, boolean considerSupers) {
return ObjectTeamsTransformer.isWeavable(className.replace('.', '/'))
&& WeavableRegionReader.isWeavable(className);
}
@@ -84,7 +88,7 @@ public class ObjectTeamsTransformer implements ClassFileTransformer {
AbstractBoundClass clazz = classRepo.peekBoundClass(classId);
String sourceClassName = className.replace('/','.');
- if (!weavingContext.isWeavable(sourceClassName) || loader == null) {
+ if (!weavingContext.isWeavable(sourceClassName, false) || loader == null) {
if (clazz != null) {
if (isWeavable(className) && clazz.needsWeaving()) {
// only print out for now, exceptions thrown by us are silently caught by TransformerManager.

Back to the top