Skip to content

Commit 96f6b1a

Browse files
Merge pull request #258 from alibaba/develop-for-20191212
Develop for 20191212
2 parents 4c45b17 + 2a19264 commit 96f6b1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1212
-403
lines changed

.travis.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: generic
2+
3+
cache:
4+
directories:
5+
- "$HOME/.m2/repository"
6+
7+
jdk:
8+
- openjdk8
9+
10+
script:
11+
- PATH=$(echo "$PATH" | sed -e 's/:\/usr\/local\/lib\/jvm\/openjdk11\/bin//')
12+
- JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
13+
- mvn -Pdefault clean cobertura:cobertura -Dmaven.test.skip=false
14+
15+
after_success:
16+
- bash <(curl -s https://codecov.io/bash)

.travis.yml.backup

-13
This file was deleted.

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ![BANNER](https://github.com/alibaba/jvm-sandbox/wiki/img/BANNER.png)
22

3+
[![Build Status](https://travis-ci.org/alibaba/jvm-sandbox.svg?branch=master)](https://travis-ci.org/alibaba/jvm-sandbox)
4+
[![codecov](https://codecov.io/gh/alibaba/jvm-sandbox/branch/master/graph/badge.svg)](https://codecov.io/gh/alibaba/jvm-sandbox)
35
![license](https://img.shields.io/github/license/alibaba/arthas.svg)
46
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/alibaba/jvm-sandbox.svg)](http://isitmaintained.com/project/alibaba/jvm-sandbox "Average time to resolve an issue")
57
[![Percentage of issues still open](http://isitmaintained.com/badge/open/alibaba/jvm-sandbox.svg)](http://isitmaintained.com/project/alibaba/jvm-sandbox "Percentage of issues still open")

bin/sandbox.sh

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
typeset SANDBOX_HOME_DIR
1111
[[ -z ${SANDBOX_HOME_DIR} ]] && SANDBOX_HOME_DIR=${PWD}/..
1212

13+
# define current SANDBOX_USER
14+
typeset SANDBOX_USER=${USER}
15+
[[ -z ${SANDBOX_USER} ]] && SANDBOX_USER=$(whoami)
16+
1317
# define sandbox's network
1418
typeset SANDBOX_SERVER_NETWORK
1519

@@ -67,7 +71,7 @@ usage: ${0} [h] [<p:> [vlRFfu:a:A:d:m:I:P:C:X]]
6771
Prints loaded module list
6872
6973
70-
-F : flush
74+
-F : force flush
7175
Force flush the sandbox\`s user module library.
7276
7377
flush reload user module library\`s module jar file.
@@ -79,7 +83,7 @@ usage: ${0} [h] [<p:> [vlRFfu:a:A:d:m:I:P:C:X]]
7983
- ${SANDBOX_HOME_DIR}/sandbox-module/
8084
8185
82-
-f : force flush
86+
-f : soft flush
8387
Soft flush the sandbox\`s user module library.
8488
8589
flush user module library\`s module which module jar file was changed.
@@ -180,8 +184,8 @@ check_permission() {
180184
exit_on_err 1 "permission denied, java process ${TARGET_JVM_PID} is not existed."
181185

182186
# check attach
183-
pgrep -U "${USER}" | grep "${TARGET_JVM_PID}" > /dev/null ||
184-
exit_on_err 1 "permission denied, ${USER} is not allow attach to ${TARGET_JVM_PID}."
187+
pgrep -U "${SANDBOX_USER}" | grep "${TARGET_JVM_PID}" > /dev/null ||
188+
exit_on_err 1 "permission denied, ${SANDBOX_USER} is not allow attach to ${TARGET_JVM_PID}."
185189

186190
# check $HOME is writeable
187191
[[ ! -w ${HOME} ]] &&

pom.xml

+37-2
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,48 @@
55

66
<groupId>com.alibaba.jvm.sandbox</groupId>
77
<artifactId>sandbox</artifactId>
8-
<version>1.3.0</version>
8+
<version>1.3.1-SNAPSHOT</version>
99
<packaging>pom</packaging>
1010

1111
<name>sandbox ${sandbox.version}</name>
1212

1313
<properties>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15-
<sandbox.version>1.3.0</sandbox.version>
15+
<sandbox.version>1.3.1-SNAPSHOT</sandbox.version>
1616
</properties>
1717

18+
<profiles>
19+
20+
<!-- 默认 -->
21+
<profile>
22+
<id>default</id>
23+
<properties>
24+
<tools-jar>${java.home}/../lib/tools.jar</tools-jar>
25+
</properties>
26+
<activation>
27+
<activeByDefault>true</activeByDefault>
28+
</activation>
29+
</profile>
30+
31+
</profiles>
32+
33+
<reporting>
34+
<plugins>
35+
<plugin>
36+
<groupId>org.apache.maven.plugins</groupId>
37+
<artifactId>maven-javadoc-plugin</artifactId>
38+
<version>3.0.0-M1</version>
39+
</plugin>
40+
<plugin>
41+
<groupId>org.codehaus.mojo</groupId>
42+
<artifactId>cobertura-maven-plugin</artifactId>
43+
<version>2.7</version>
44+
</plugin>
45+
</plugins>
46+
</reporting>
47+
1848
<build>
49+
1950
<pluginManagement>
2051
<plugins>
2152
<plugin>
@@ -42,6 +73,8 @@
4273
<showDeprecation>true</showDeprecation>
4374
</configuration>
4475
</plugin>
76+
77+
<!--
4578
<plugin>
4679
<groupId>org.apache.maven.plugins</groupId>
4780
<artifactId>maven-javadoc-plugin</artifactId>
@@ -55,6 +88,8 @@
5588
</execution>
5689
</executions>
5790
</plugin>
91+
-->
92+
5893
<plugin>
5994
<groupId>org.apache.maven.plugins</groupId>
6095
<artifactId>maven-source-plugin</artifactId>

sandbox-agent/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.alibaba.jvm.sandbox</groupId>
88
<artifactId>sandbox</artifactId>
9-
<version>1.3.0</version>
9+
<version>1.3.1-SNAPSHOT</version>
1010
</parent>
1111
<artifactId>sandbox-agent</artifactId>
1212
<name>sandbox-agent ${sandbox.version}</name>

sandbox-api/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.alibaba.jvm.sandbox</groupId>
88
<artifactId>sandbox</artifactId>
9-
<version>1.3.0</version>
9+
<version>1.3.1-SNAPSHOT</version>
1010
</parent>
1111
<artifactId>sandbox-api</artifactId>
1212
<name>sandbox-api ${sandbox.version}</name>

sandbox-api/src/main/java/com/alibaba/jvm/sandbox/api/listener/ext/Advice.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public class Advice implements Attachment {
3838
/**
3939
* 构造通知
4040
*
41-
* @param processId {@link InvokeEvent#processId}
42-
* @param invokeId {@link InvokeEvent#invokeId}
41+
* @param processId {@link InvokeEvent#processId}
42+
* @param invokeId {@link InvokeEvent#invokeId}
4343
* @param behaviorLazyGet 触发事件的行为(懒加载)
44-
* @param loader 触发事件的行为所在ClassLoader
45-
* @param parameterArray 触发事件的行为入参
46-
* @param target 触发事件所归属的对象实例
44+
* @param loader 触发事件的行为所在ClassLoader
45+
* @param parameterArray 触发事件的行为入参
46+
* @param target 触发事件所归属的对象实例
4747
*/
4848
Advice(final int processId,
4949
final int invokeId,

sandbox-api/src/main/java/com/alibaba/jvm/sandbox/api/listener/ext/AdviceAdapterListener.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,18 @@ private void switchEvent(final OpStack opStack,
5959
bEvent.processId,
6060
bEvent.invokeId,
6161
new LazyGet<Behavior>() {
62+
63+
private final ClassLoader _loader = loader;
64+
private final String _javaClassName = bEvent.javaClassName;
65+
private final String _javaMethodName = bEvent.javaMethodName;
66+
private final String _javaMethodDesc = bEvent.javaMethodDesc;
67+
6268
@Override
6369
protected Behavior initialValue() throws Throwable {
6470
return toBehavior(
65-
toClass(loader, bEvent.javaClassName),
66-
bEvent.javaMethodName,
67-
bEvent.javaMethodDesc
71+
toClass(_loader, _javaClassName),
72+
_javaMethodName,
73+
_javaMethodDesc
6874
);
6975
}
7076
},

sandbox-api/src/main/java/com/alibaba/jvm/sandbox/api/listener/ext/EventWatchBuilder.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ public interface IBuildingForBehavior {
190190
*/
191191
EventWatcher onWatch(AdviceListener adviceListener);
192192

193+
/**
194+
* 观察器
195+
*
196+
* @param adviceListener advice监听器
197+
* @param eventTypeArray 需要被监听的事件列表(参数废弃)
198+
* @return this
199+
* @deprecated 根据 #256 的建议,这个接口废弃,请采用 {@link #onWatch(AdviceListener)} 代替
200+
*/
201+
@Deprecated
193202
EventWatcher onWatch(AdviceListener adviceListener, Event.Type... eventTypeArray);
194203

195204
EventWatcher onWatch(EventListener eventListener, Event.Type... eventTypeArray);
@@ -639,16 +648,13 @@ public IBuildingForWatching onWatching() {
639648

640649
@Override
641650
public EventWatcher onWatch(AdviceListener adviceListener) {
642-
return onWatch(adviceListener, EMPTY);
651+
return build(new AdviceAdapterListener(adviceListener), null, BEFORE, RETURN, THROWS, IMMEDIATELY_RETURN, IMMEDIATELY_THROWS);
643652
}
644653

654+
@Deprecated
645655
@Override
646656
public EventWatcher onWatch(final AdviceListener adviceListener, Event.Type... eventTypeArray) {
647-
if (eventTypeArray == null
648-
|| eventTypeArray.length == 0) {
649-
return build(new AdviceAdapterListener(adviceListener), null, BEFORE, RETURN, THROWS, IMMEDIATELY_RETURN, IMMEDIATELY_THROWS);
650-
}
651-
return build(new AdviceAdapterListener(adviceListener), null, eventTypeArray);
657+
return onWatch(adviceListener);
652658
}
653659

654660
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.alibaba.jvm.sandbox.qatest.api.issues;
2+
3+
import com.alibaba.jvm.sandbox.api.event.Event;
4+
import com.alibaba.jvm.sandbox.api.listener.ext.AdviceListener;
5+
import com.alibaba.jvm.sandbox.api.listener.ext.EventWatchBuilder;
6+
import com.alibaba.jvm.sandbox.qatest.api.mock.MockForBuilderModuleEventWatcher;
7+
import com.alibaba.jvm.sandbox.qatest.api.util.ApiQaArrayUtils;
8+
import org.junit.Assert;
9+
import org.junit.Test;
10+
11+
import static com.alibaba.jvm.sandbox.api.event.Event.Type.CALL_BEFORE;
12+
13+
public class TestIssues256 {
14+
15+
@Test
16+
public void test$$onBehavior$$onWatch$without_special_EventType() {
17+
18+
final MockForBuilderModuleEventWatcher mockForBuilderModuleEventWatcher
19+
= new MockForBuilderModuleEventWatcher();
20+
21+
new EventWatchBuilder(mockForBuilderModuleEventWatcher)
22+
.onClass(String.class)
23+
.onBehavior("toString")
24+
.onWatch(new AdviceListener(), CALL_BEFORE);
25+
26+
Assert.assertEquals(5, mockForBuilderModuleEventWatcher.getEventTypeArray().length);
27+
Assert.assertTrue(ApiQaArrayUtils.has(Event.Type.RETURN, mockForBuilderModuleEventWatcher.getEventTypeArray()));
28+
Assert.assertTrue(ApiQaArrayUtils.has(Event.Type.THROWS, mockForBuilderModuleEventWatcher.getEventTypeArray()));
29+
Assert.assertTrue(ApiQaArrayUtils.has(Event.Type.BEFORE, mockForBuilderModuleEventWatcher.getEventTypeArray()));
30+
Assert.assertTrue(ApiQaArrayUtils.has(Event.Type.IMMEDIATELY_RETURN, mockForBuilderModuleEventWatcher.getEventTypeArray()));
31+
Assert.assertTrue(ApiQaArrayUtils.has(Event.Type.IMMEDIATELY_THROWS, mockForBuilderModuleEventWatcher.getEventTypeArray()));
32+
33+
}
34+
35+
}

sandbox-api/src/test/java/com/alibaba/jvm/sandbox/api/util/GaStringUtilsTests.java sandbox-api/src/test/java/com/alibaba/jvm/sandbox/qatest/api/util/GaStringUtilsTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
package com.alibaba.jvm.sandbox.api.util;
1+
package com.alibaba.jvm.sandbox.qatest.api.util;
22

3+
import com.alibaba.jvm.sandbox.api.util.GaStringUtils;
34
import org.junit.Assert;
45
import org.junit.Test;
56

sandbox-common-api/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>sandbox</artifactId>
88
<groupId>com.alibaba.jvm.sandbox</groupId>
9-
<version>1.3.0</version>
9+
<version>1.3.1-SNAPSHOT</version>
1010
</parent>
1111
<artifactId>sandbox-common-api</artifactId>
1212
<name>sandbox-common-api ${sandbox.version}</name>

sandbox-core/pom.xml

+5-18
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.alibaba.jvm.sandbox</groupId>
88
<artifactId>sandbox</artifactId>
9-
<version>1.3.0</version>
9+
<version>1.3.1-SNAPSHOT</version>
1010
</parent>
1111
<artifactId>sandbox-core</artifactId>
1212
<name>sandbox-core ${sandbox.version}</name>
@@ -77,7 +77,7 @@
7777
<artifactId>tools</artifactId>
7878
<version>1.8</version>
7979
<scope>system</scope>
80-
<systemPath>${java.home}/../lib/tools.jar</systemPath>
80+
<systemPath>${tools-jar}</systemPath>
8181
</dependency>
8282

8383
<dependency>
@@ -150,22 +150,17 @@
150150
<dependency>
151151
<groupId>org.ow2.asm</groupId>
152152
<artifactId>asm</artifactId>
153-
<version>7.0</version>
153+
<version>7.2</version>
154154
</dependency>
155155
<dependency>
156156
<groupId>org.ow2.asm</groupId>
157157
<artifactId>asm-commons</artifactId>
158-
<version>7.0</version>
158+
<version>7.2</version>
159159
</dependency>
160160
<dependency>
161161
<groupId>org.ow2.asm</groupId>
162162
<artifactId>asm-util</artifactId>
163-
<version>7.0</version>
164-
</dependency>
165-
<dependency>
166-
<groupId>org.apache.commons</groupId>
167-
<artifactId>commons-pool2</artifactId>
168-
<version>2.4.2</version>
163+
<version>7.2</version>
169164
</dependency>
170165

171166
<dependency>
@@ -174,13 +169,5 @@
174169
<version>18.0</version>
175170
</dependency>
176171

177-
<!-- ant
178-
<dependency>
179-
<groupId>org.apache.ant</groupId>
180-
<artifactId>ant</artifactId>
181-
<version>1.7.0</version>
182-
</dependency>
183-
-->
184-
185172
</dependencies>
186173
</project>

sandbox-core/src/main/java/com/alibaba/jvm/sandbox/core/JvmSandbox.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import com.alibaba.jvm.sandbox.core.enhance.weaver.EventListenerHandler;
44
import com.alibaba.jvm.sandbox.core.manager.CoreModuleManager;
5+
import com.alibaba.jvm.sandbox.core.manager.impl.DefaultCoreLoadedClassDataSource;
56
import com.alibaba.jvm.sandbox.core.manager.impl.DefaultCoreModuleManager;
6-
import com.alibaba.jvm.sandbox.core.manager.impl.DefaultLoadedClassDataSource;
77
import com.alibaba.jvm.sandbox.core.manager.impl.DefaultProviderManager;
8+
import com.alibaba.jvm.sandbox.core.util.SandboxProtector;
89
import com.alibaba.jvm.sandbox.core.util.SpyUtils;
910

1011
import java.lang.instrument.Instrumentation;
@@ -21,12 +22,12 @@ public JvmSandbox(final CoreConfigure cfg,
2122
final Instrumentation inst) {
2223
EventListenerHandler.getSingleton();
2324
this.cfg = cfg;
24-
this.coreModuleManager = new DefaultCoreModuleManager(
25+
this.coreModuleManager = SandboxProtector.instance.protectProxy(CoreModuleManager.class, new DefaultCoreModuleManager(
2526
cfg,
2627
inst,
27-
new DefaultLoadedClassDataSource(inst, cfg.isEnableUnsafe()),
28+
new DefaultCoreLoadedClassDataSource(inst, cfg.isEnableUnsafe()),
2829
new DefaultProviderManager(cfg)
29-
);
30+
));
3031

3132
init();
3233
}

0 commit comments

Comments
 (0)