Skip to content

Commit 996fbd5

Browse files
committed
Stable version of thread-safe JMPLib
1 parent f93bb82 commit 996fbd5

File tree

13 files changed

+254
-27
lines changed

13 files changed

+254
-27
lines changed

lib/jmplib-with-dependencies.jar

809 Bytes
Binary file not shown.

lib/jmplib.jar

809 Bytes
Binary file not shown.

src/jmplib/SimpleEvaluator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public SimpleEvaluator() {
4848
* {@inheritDoc}
4949
*/
5050
public IEvaluator createEvaluator() {
51+
if (!JMPlibConfig.getInstance().isAgentLoaded())
52+
throw new IllegalStateException("The Updater Agent has not been loaded. JMPLib cannot be used. Please do" +
53+
" not forget to add the -javaagent:./lib/jmplib.jar parameter when running the application");
5154
if (_instance == null) {
5255
if (JMPlibConfig.getInstance().getConfigureAsThreadSafe()) {
5356
_instance = new ThreadSafeSimpleEvaluator();

src/jmplib/SimpleIntercessor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package jmplib;
22

3+
import jmplib.config.JMPlibConfig;
34
import jmplib.exceptions.StructuralIntercessionException;
45
import jmplib.reflect.Class;
56
import jmplib.reflect.TypeVariable;
@@ -35,6 +36,9 @@ public class SimpleIntercessor implements IIntercessor {
3536
* {@inheritDoc}
3637
*/
3738
public IIntercessor createIntercessor() {
39+
if (!JMPlibConfig.getInstance().isAgentLoaded())
40+
throw new IllegalStateException("The Updater Agent has not been loaded. JMPLib cannot be used. Please do" +
41+
" not forget to add the -javaagent:./lib/jmplib.jar parameter when running the application");
3842
return _instance;
3943
}
4044

src/jmplib/TransactionalIntercessor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public TransactionalIntercessor() {
5050
* {@inheritDoc}
5151
*/
5252
public IIntercessor createIntercessor() {
53+
if (!JMPlibConfig.getInstance().isAgentLoaded())
54+
throw new IllegalStateException("The Updater Agent has not been loaded. JMPLib cannot be used. Please do" +
55+
" not forget to add the -javaagent:./lib/jmplib.jar parameter when running the application");
56+
5357
return new TransactionalIntercessor();
5458
}
5559

src/jmplib/agent/UpdaterAgent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public static void premain(String agentArgs, Instrumentation inst) {
5353
if (agentArgs.equals(JMPlibConfig.THREAD_SAFE_OPTION))
5454
JMPlibConfig.getInstance().setConfigureAsThreadSafe(true);
5555
}
56+
JMPlibConfig.getInstance().setAgentLoaded(true);
5657
run("premain", agentArgs, inst);
5758
} catch (StructuralIntercessionException e) {
5859
throw new RuntimeException("Intrumentation error", e);

src/jmplib/asm/visitor/ClassCacherVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ private void generateInvoker(String name, String desc, String[] exceptions) {
256256
clazz.getSimpleName() + "_NewVersion_0", //%3
257257
paramsNames, //%4
258258
(returnClassName.equals("void") ? "" : returnClassName + " ret_value = "), //%5
259-
(returnClassName.equals("void") ? "" : " return ret_value;"), //%6
259+
(returnClassName.equals("void") ? "return;" : " return ret_value;"), //%6
260260
(returnClassName.equals("void") ? "" : "(" + returnClassName+")"), //%7
261261
(paramsNames.equals("") ? "" : ", " + paramsNames), //%8
262262
(paramTypes.equals("") ? "" : ", " + paramTypes)}; //%9

src/jmplib/config/JMPlibConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ public class JMPlibConfig {
3636
public static final String THREAD_SAFE_OPTION = "thread_safety";
3737
private boolean configureAsThreadSafe = false;
3838

39+
public boolean isAgentLoaded() {
40+
return agentLoaded;
41+
}
42+
43+
public void setAgentLoaded(boolean agentLoaded) {
44+
this.agentLoaded = agentLoaded;
45+
}
46+
47+
private boolean agentLoaded = false;
48+
3949
private JMPlibConfig() {
4050
configFileExist = new File(PROPERTY_FILE_NAME).exists();
4151
originalClassPath = load(ORIGINAL_CLASS_PATH_KEY).orElse(DEFAULT_ORIGINAL_CLASS_PATH);

src/jmplib/primitives/MethodPrimitive.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ private String getProperReturnClassName() {
8585
//For arrays
8686
if ((this.returnClass.toString().startsWith("[")) || (this.returnClass.toString().startsWith("class [")))
8787
return this.returnClass.getSimpleName();
88-
return returnClass.toString();
88+
String strReturn = returnClass.toString();
89+
if (strReturn.startsWith("class "))
90+
strReturn = strReturn.substring("class ".length(), strReturn.length());
91+
return strReturn;
8992
}
9093
/**
9194
* Generates the body of an invoker method
@@ -100,7 +103,7 @@ protected String getBodyInvoker(String name, String paramsNames, String paramTyp
100103
clazz.getSimpleName() + "_NewVersion_"
101104
+ (classContent.isUpdated() ? classContent.getVersion() - 1 : classContent.getVersion()),
102105
paramsNames, (returnClass.getName().equals("void") ? "" : getProperReturnClassName() + " ret_value = "),
103-
(returnClass.getName().equals("void") ? "" : " return ret_value;"),
106+
(returnClass.getName().equals("void") ? "return;" : " return ret_value;"),
104107
(returnClass.getName().equals("void") ? "" : "(" + getProperReturnClassName()+")"),
105108
(paramsNames.equals("") ? "" : ", " + paramsNames), //%8
106109
(paramTypes.equals("") ? "" : ", " + paramTypes)}; //%9

0 commit comments

Comments
 (0)