[jboss-svn-commits] JBL Code SVN: r29626 - in labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman: rule and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Oct 15 13:05:06 EDT 2009
Author: adinn
Date: 2009-10-15 13:05:05 -0400 (Thu, 15 Oct 2009)
New Revision: 29626
Modified:
labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/TransformListener.java
labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/Transformer.java
labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/Rule.java
labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/compiler/Compiler.java
labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/helper/Helper.java
Log:
added remaining changes to ensure triggering does not happen inside the rule engine -- fixes BYTEMAN-50
Modified: labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/TransformListener.java
===================================================================
--- labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/TransformListener.java 2009-10-15 17:04:49 UTC (rev 29625)
+++ labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/TransformListener.java 2009-10-15 17:05:05 UTC (rev 29626)
@@ -1,6 +1,7 @@
package org.jboss.byteman.agent;
import org.jboss.byteman.agent.Retransformer;
+import org.jboss.byteman.rule.Rule;
import java.net.ServerSocket;
import java.net.Socket;
@@ -49,6 +50,11 @@
public static synchronized boolean terminate()
{
+ // we don't want the listener shutdown to be aborted because of triggered rules
+ boolean enabled = true;
+ try {
+ enabled = Rule.disableTriggers();
+
if (theTransformListener != null) {
try {
theServerSocket.close();
@@ -69,10 +75,19 @@
}
return true;
+ } finally {
+ if (enabled) {
+ Rule.disableTriggers();
+ }
+ }
}
public void run()
{
+ // we don't want to see any triggers in the listener thread
+
+ Rule.disableTriggers();
+
while (true) {
if (theServerSocket.isClosed()) {
return;
Modified: labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/Transformer.java
===================================================================
--- labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/Transformer.java 2009-10-15 17:04:49 UTC (rev 29625)
+++ labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/agent/Transformer.java 2009-10-15 17:05:05 UTC (rev 29626)
@@ -45,13 +45,6 @@
*/
public class Transformer implements ClassFileTransformer {
- private static Transformer theTransformer = null;
-
- public static Transformer getTheTransformer()
- {
- return theTransformer;
- }
-
/**
* constructor allowing this transformer to be provided with access to the JVM's instrumentation
* implementation
@@ -61,7 +54,6 @@
public Transformer(Instrumentation inst, List<String> scriptPaths, List<String> scriptTexts, boolean isRedefine)
throws Exception
{
- theTransformer = this;
this.inst = inst;
this.isRedefine = isRedefine;
targetToScriptMap = new HashMap<String, List<RuleScript>>();
@@ -237,6 +229,11 @@
public void installBootScripts() throws Exception
{
+ boolean enabled = true;
+ try {
+ enabled = Rule.disableTriggers();
+
+
// check for scrips which apply to classes already loaded during bootstrap and retransform those classes
// so that rule triggers are injected
@@ -295,6 +292,11 @@
Class<?>[] transformedArray = new Class<?>[omitted.size()];
inst.retransformClasses(omitted.toArray(transformedArray));
}
+ } finally {
+ if (enabled) {
+ Rule.enableTriggers();
+ }
+ }
}
/**
@@ -360,6 +362,10 @@
byte[] classfileBuffer)
throws IllegalClassFormatException
{
+ boolean enabled = true;
+ try {
+ enabled = Rule.disableTriggers();
+
byte[] newBuffer = classfileBuffer;
// we only transform certain classes -- we do allow bootstrap classes whose loader is null
// but we exclude byteman classes and java.lang classes
@@ -421,6 +427,11 @@
} else {
return null;
}
+ } finally {
+ if (enabled) {
+ Rule.enableTriggers();
+ }
+ }
}
/* switches controlling behaviour of transformer */
@@ -729,19 +740,19 @@
}
}
- public void maybeDumpClass(String fullName, byte[] bytes)
+ public static void maybeDumpClass(String fullName, byte[] bytes)
{
if (dumpGeneratedClasses) {
dumpClass(fullName, bytes);
}
}
- private void dumpClass(String fullName, byte[] bytes)
+ private static void dumpClass(String fullName, byte[] bytes)
{
dumpClass(fullName, bytes, null);
}
- private void dumpClass(String fullName, byte[] bytes, byte[] oldBytes)
+ private static void dumpClass(String fullName, byte[] bytes, byte[] oldBytes)
{
int dotIdx = fullName.lastIndexOf('.');
@@ -776,7 +787,7 @@
}
}
- private boolean ensureDumpDirectory(String fileName)
+ private static boolean ensureDumpDirectory(String fileName)
{
File file = new File(fileName);
if (file.exists()) {
Modified: labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/Rule.java
===================================================================
--- labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/Rule.java 2009-10-15 17:04:49 UTC (rev 29625)
+++ labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/Rule.java 2009-10-15 17:05:05 UTC (rev 29626)
@@ -35,7 +35,6 @@
import org.jboss.byteman.rule.helper.Helper;
import org.jboss.byteman.rule.helper.InterpretedHelper;
import org.jboss.byteman.agent.Location;
-import org.jboss.byteman.agent.LocationType;
import org.jboss.byteman.agent.Transformer;
import org.jboss.byteman.agent.RuleScript;
import org.objectweb.asm.Opcodes;
@@ -339,11 +338,11 @@
* disable triggering of rules inside the current thread
* @return true if triggering was previously enabled and false if it was already disabled
*/
- public boolean disableTriggers()
+ public static boolean disableTriggers()
{
- Rule enabledRule = recursionGuard.get();
- if (enabledRule == null) {
- recursionGuard.set(this);
+ Boolean enabled = isEnabled.get();
+ if (enabled == null) {
+ isEnabled.set(Boolean.FALSE);
return true;
}
@@ -354,30 +353,24 @@
* enable triggering of rules inside the current thread
* @return true if triggering was previously enabled and false if it was already disabled
*/
- public boolean enableTriggers()
+ public static boolean enableTriggers()
{
- Rule enabledRule = recursionGuard.get();
- if (enabledRule == null) {
- return true;
- } else {
- recursionGuard.remove();
- return true;
+ Boolean enabled = isEnabled.get();
+ if (enabled != null) {
+ isEnabled.remove();
+ return false;
}
+
+ return true;
}
/**
* check if triggering of rules is enabled inside the current thread
* @return true if triggering is enabled and false if it is disabled
*/
- public boolean isTriggeringEnabled()
+ public static boolean isTriggeringEnabled()
{
- Rule enabledRule = recursionGuard.get();
- if (enabledRule == null) {
- return true;
- } else {
- recursionGuard.remove();
- return true;
- }
+ return isEnabled.get() == null;
}
/**
@@ -394,9 +387,10 @@
if (!checked) {
// ensure we don't trigger any code inside the type check or compile
// n.b. we may still allow recursive triggering while executing
- boolean triggerEnabled = disableTriggers();
+ boolean triggerEnabled = false;
String detail = "";
try {
+ triggerEnabled = disableTriggers();
typeCheck();
compile();
checked = true;
@@ -546,9 +540,9 @@
*/
public static void execute(String key, Object recipient, Object[] args) throws ExecuteException
{
- Rule inTypeCheckCompile = recursionGuard.get();
- if (inTypeCheckCompile != null) {
- // we don't trigger code while we are doing ruel type checking or compilation
+ boolean enabled = isTriggeringEnabled();
+ if (!enabled) {
+ // we don't trigger code while we are doing rule housekeeping
return;
}
Rule rule = ruleKeyMap.get(key);
@@ -746,7 +740,15 @@
{
return helperClass;
}
-
+
+ /**
+ * flag true if debugging of rule parsing is desired and false if it should not be performed
+ */
private static boolean debugParse = (System.getProperty("org.jboss.byteman.rule.debug") != null ? true : false);
- private static ThreadLocal<Rule> recursionGuard = new ThreadLocal<Rule>();
+
+ /**
+ * Thread local holding a per thread Boolean which is true if triggering is disabled and false if triggering is
+ * enabled
+ */
+ private static ThreadLocal<Boolean> isEnabled = new ThreadLocal<Boolean>();
}
Modified: labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/compiler/Compiler.java
===================================================================
--- labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/compiler/Compiler.java 2009-10-15 17:04:49 UTC (rev 29625)
+++ labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/compiler/Compiler.java 2009-10-15 17:05:05 UTC (rev 29626)
@@ -74,7 +74,7 @@
byte[] classBytes = compileBytes(rule, helperClass, helperName, compiledHelperName, compileToBytecode);
String externalName = compiledHelperName.replaceAll("/", ".");
// dump the compiled class bytes if required
- Transformer.getTheTransformer().maybeDumpClass(externalName, classBytes);
+ Transformer.maybeDumpClass(externalName, classBytes);
// ensure the class is loaded
// think we need to load the generated helper using the class loader of the trigger class
ClassLoader loader = rule.getLoader();
Modified: labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/helper/Helper.java
===================================================================
--- labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/helper/Helper.java 2009-10-15 17:04:49 UTC (rev 29625)
+++ labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/helper/Helper.java 2009-10-15 17:05:05 UTC (rev 29626)
@@ -914,9 +914,9 @@
public void setTriggering(boolean enabled)
{
if (enabled) {
- rule.enableTriggers();
+ Rule.enableTriggers();
} else {
- rule.disableTriggers();
+ Rule.disableTriggers();
}
}
More information about the jboss-svn-commits
mailing list