Permalink
Browse files

correct stack height computation for fields -- fixes BYTEMAN-253

  • Loading branch information...
1 parent f85ab35 commit aaeb144a2195b49afa96aaba67b2118fadcc7612 @adinn adinn committed Dec 3, 2013
View
30 agent/pom.xml
@@ -856,6 +856,21 @@
<argLine>-javaagent:${project.build.directory}/byteman-${project.version}.jar=script:${project.build.testOutputDirectory}/scripts/bugfixes/TestBooleanComparisons.btm</argLine>
</configuration>
</execution>
+ <execution>
+ <id>bugfixes.TestStackHeight</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/TestStackHeight.class</include>
+ </includes>
+ <argLine>-javaagent:${project.build.directory}/byteman-${project.version}.jar=script:${project.build.testOutputDirectory}/scripts/bugfixes/TestStackHeight.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
@@ -1616,6 +1631,21 @@
<argLine>-Dorg.jboss.byteman.compile.to.bytecode -javaagent:${project.build.directory}/byteman-${project.version}.jar=script:${project.build.testOutputDirectory}/scripts/bugfixes/TestBooleanComparisons.btm</argLine>
</configuration>
</execution>
+ <execution>
+ <id>bugfixes.TestStackHeight.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/TestStackHeight.class</include>
+ </includes>
+ <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>
<!-- 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
4 agent/src/main/java/org/jboss/byteman/rule/RuleElement.java
@@ -361,6 +361,10 @@ protected void compileBooleanConversion(Type fromType, Type toType, MethodVisito
throws CompileException
{
if (toType == Type.Z) {
+ if (fromType == Type.OBJECT) {
+ fromType = Type.BOOLEAN;
+ mv.visitTypeInsn(Opcodes.CHECKCAST, fromType.getInternalName(false, true));
+ }
assert fromType == Type.BOOLEAN;
compileUnbox(fromType, toType, mv, compileContext);
} else {
View
67 agent/src/test/java/org/jboss/byteman/tests/bugfixes/TestStackHeight.java
@@ -0,0 +1,67 @@
+/*
+ * 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-254 to ensure that compilation of field expressions in
+ * conditions does not fail with an invalid stack height
+ */
+package org.jboss.byteman.tests.bugfixes;
+
+import org.jboss.byteman.tests.Test;
+
+public class TestStackHeight extends Test
+{
+ private boolean testField;
+
+ public TestStackHeight()
+ {
+ super("TestStackHeight");
+ testField = false;
+ }
+
+ public void setTestField(boolean value)
+ {
+ log("setting field " + testField);
+ testField = value;
+ log("set field " + testField);
+ }
+
+ public boolean isTestField()
+ {
+ return testField;
+ }
+ public void test()
+ {
+ TestStackHeight test = new TestStackHeight();
+ setTestField(true);
+ }
+
+ @Override
+ public String getExpected() {
+ logExpected("setting field false");
+ logExpected("set field true");
+
+ return super.getExpected();
+ }
+}
View
33 agent/src/test/resources/scripts/bugfixes/TestStackHeight.btm
@@ -0,0 +1,33 @@
+##############################################################################
+# 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-254 to ensure that compilation of field expressions in
+# conditions does not fail with an invalid stack height
+
+RULE TestStackHeight
+CLASS org.jboss.byteman.tests.bugfixes.TestStackHeight
+METHOD setTestField(boolean)
+AT ENTRY
+IF $this.testField
+DO $this.log("should not get here!")
+ENDRULE

0 comments on commit aaeb144

Please sign in to comment.