Skip to content
Browse files

use correct type for checkcast at update of local var -- fixes BYTEMA…

…N-252
  • Loading branch information...
1 parent aaeb144 commit 742b5009e31d39b5adf93603ce5fb7ad10c0f8d6 @adinn committed Dec 3, 2013
View
30 agent/pom.xml
@@ -871,6 +871,21 @@
<argLine>-javaagent:${project.build.directory}/byteman-${project.version}.jar=script:${project.build.testOutputDirectory}/scripts/bugfixes/TestStackHeight.btm</argLine>
</configuration>
</execution>
+ <execution>
+ <id>bugfixes.TestLocalUpdateType</id>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ <configuration>
+ <forkMode>once</forkMode>
+ <includes>
+ <include>org/jboss/byteman/tests/bugfixes/TestLocalUpdateType.class</include>
+ </includes>
+ <argLine>-javaagent:${project.build.directory}/byteman-${project.version}.jar=script:${project.build.testOutputDirectory}/scripts/bugfixes/TestLocalUpdateType.btm</argLine>
+ </configuration>
+ </execution>
<!-- dynamic rule submission
n.b. submit test does not use a script on the command line
instead it sets listener true and uplaods the rules from the test program
@@ -1646,6 +1661,21 @@
<argLine>-Dorg.jboss.byteman.compile.to.bytecode -javaagent:${project.build.directory}/byteman-${project.version}.jar=script:${project.build.testOutputDirectory}/scripts/bugfixes/TestStackHeight.btm</argLine>
</configuration>
</execution>
+ <execution>
+ <id>bugfixes.TestLocalUpdateType.compiled</id>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ <configuration>
+ <forkMode>once</forkMode>
+ <includes>
+ <include>org/jboss/byteman/tests/bugfixes/TestLocalUpdateType.class</include>
+ </includes>
+ <argLine>-Dorg.jboss.byteman.compile.to.bytecode -javaagent:${project.build.directory}/byteman-${project.version}.jar=script:${project.build.testOutputDirectory}/scripts/bugfixes/TestLocalUpdateType.btm</argLine>
+ </configuration>
+ </execution>
<!-- dynamic rule submission compiled
submit test does not use a script on the command line
instead it sets listener true and uplaods the rules from the test program
View
13 agent/src/main/java/org/jboss/byteman/agent/adapter/RuleGeneratorAdapter.java
@@ -271,7 +271,7 @@ private void initLocalTypes()
// owner of this method is an object
// localTypes.add(Type.getType(Object.class));
String name = getTriggerClassName().replace('.', '/');
- if ((access | Opcodes.ACC_STATIC) == 0) {
+ if ((access & Opcodes.ACC_STATIC) == 0) {
// an instance method so slot 0 will contain the target object
localTypes.add(Type.getType("L" + name + ";"));
}
@@ -1392,12 +1392,11 @@ public void visitVarInsn(final int opcode, final int var)
size = 2;
break;
case Opcodes.ASTORE:
- // we don't know exactly what type this is but at least we know it is an object
- {
- String name = getTriggerClassName().replace('.', '/');
- type = Type.getType("L" + name + ";");
- }
- // type = Type.getType(Object.class);
+ // we don't know exactly what type this is but at least we know it is an object
+ // we need to correct for this when injecting trigger code to update the local
+ // luckily we can use the binding type derived during the check phase to idenitfy
+ // the actual local type
+ type = Type.getType(Object.class);
break;
}
if (var < nextLocal) {
View
12 agent/src/main/java/org/jboss/byteman/agent/adapter/RuleTriggerMethodAdapter.java
@@ -441,6 +441,7 @@ private boolean doArgLoad(int saveSlot)
} else if (binding.isLocalVar()){
int idx = binding.getLocalIndex();
loadLocal(idx);
+ // local type may be Object when actual type is more specific but we don't care here
box(getLocalType(idx));
} else if (binding.isParamCount()){
int count = argumentTypes.length;
@@ -532,7 +533,16 @@ private void doArgUpdate()
storeArg(idx);
} else if (binding.isLocalVar()) {
int idx = binding.getLocalIndex();
- unbox(getLocalType(idx));
+ Type t = getLocalType(idx);
+ // cannot always trust locals flagged as Object type because we sometimes
+ // insert that when we see an ALOAD for a local var we do not know about.
+ // but we can rely on the descriptor in the binding which we derived during
+ // rule check processing
+ if (t.getClassName().equals("java.lang.Object")) {
+ String descriptor = binding.getDescriptor();
+ t = Type.getType("L" + descriptor.replace('.', '/') + ";");
+ }
+ unbox(t);
storeLocal(idx);
}
}
View
56 agent/src/test/java/org/jboss/byteman/tests/bugfixes/TestLocalUpdateType.java
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2013, Red Hat and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * @authors Andrew Dinn
+ */
+
+package org.jboss.byteman.tests.bugfixes;
+
+import org.jboss.byteman.tests.Test;
+
+/**
+ * Test to exercise bug reported in BYTEMAN-252
+ */
+public class TestLocalUpdateType extends Test
+{
+ public TestLocalUpdateType()
+ {
+ super("TestLocalUpdateType");
+ }
+
+ public void test()
+ {
+ String l1 = "abcd";
+ String l2;
+ try {
+ l2 = "defg";
+ System.out.println("l2[5] = " + l2.charAt(5));
+ } catch (Exception e) {
+ log("caught exception");
+ }
+ }
+
+ @Override
+ public String getExpected() {
+ logExpected("l2 = 1234567890");
+ return super.getExpected();
+ }
+}
View
34 agent/src/test/resources/scripts/bugfixes/TestLocalUpdateType.btm
@@ -0,0 +1,34 @@
+##############################################################################
+# JBoss, Home of Professional Open Source
+# Copyright 2013, Red Hat and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+#
+# @authors Andrew Dinn
+#
+# Test for BYTEMAN-252 to ensure that the injected code which installs
+# the value of a local variable updated by a rule uses the correct type
+
+RULE test local update type
+CLASS org.jboss.byteman.tests.bugfixes.TestLocalUpdateType
+METHOD test
+AFTER WRITE $l2
+IF TRUE
+DO $l2 = "1234567890";
+ $this.log("l2 = " + $l2)
+ENDRULE

0 comments on commit 742b500

Please sign in to comment.
Something went wrong with that request. Please try again.