Skip to content

Commit

Permalink
Merge pull request alibaba#134 from alibaba/develop-for-20181227
Browse files Browse the repository at this point in the history
Develop for 20181227
  • Loading branch information
dongchenxu authored Feb 1, 2019
2 parents 9f74182 + 6fb192c commit 8557ef2
Show file tree
Hide file tree
Showing 562 changed files with 6,714 additions and 5,384 deletions.
30 changes: 0 additions & 30 deletions .github/ISSUE_TEMPLATE/----.md

This file was deleted.

9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@

## for maven
pom.xml.versionsBackup
sandbox-api/target/
sandbox-common-api/target/
sandbox-core/target/
sandbox-provider-api/target/
sandbox-spy/target/
sandbox-agent/target/
sandbox-debug-module/target/
sandbox-mgr-module/target/
sandbox-mgr-provider/target/
6 changes: 0 additions & 6 deletions bin/sandbox.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,3 @@ user_module=~/.sandbox-module;
# switch the sandbox can enhance system class
unsafe.enable=true

# define the sandbox event pool arguments(min/max/total)
event.pool.enable=true
event.pool.max.total=6000
event.pool.min.idle.per.event=50
event.pool.max.idle.per.event=100
event.pool.max.total.per.event=2000
22 changes: 11 additions & 11 deletions bin/sandbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -307,43 +307,43 @@ function main() {

# -v show version
[[ ! -z ${OP_VERSION} ]] \
&& sandbox_curl_with_exit "info/version"
&& sandbox_curl_with_exit "sandbox-info/version"

# -l list loaded modules
[[ ! -z ${OP_MODULE_LIST} ]] \
&& sandbox_curl_with_exit "module-mgr/list"
&& sandbox_curl_with_exit "sandbox-module-mgr/list"

# -F force flush module
[[ ! -z ${OP_MODULE_FORCE_FLUSH} ]] \
&& sandbox_curl_with_exit "module-mgr/flush" "&force=true"
&& sandbox_curl_with_exit "sandbox-module-mgr/flush" "&force=true"

# -f flush module
[[ ! -z ${OP_MODULE_FLUSH} ]] \
&& sandbox_curl_with_exit "module-mgr/flush" "&force=false"
&& sandbox_curl_with_exit "sandbox-module-mgr/flush" "&force=false"

# -R reset sandbox
[[ ! -z ${OP_MODULE_RESET} ]] \
&& sandbox_curl_with_exit "module-mgr/reset"
&& sandbox_curl_with_exit "sandbox-module-mgr/reset"

# -u unload module
[[ ! -z ${OP_MODULE_UNLOAD} ]] \
&& sandbox_curl_with_exit "module-mgr/unload" "&action=unload&ids=${ARG_MODULE_UNLOAD}"
&& sandbox_curl_with_exit "sandbox-module-mgr/unload" "&action=unload&ids=${ARG_MODULE_UNLOAD}"

# -a active module
[[ ! -z ${OP_MODULE_ACTIVE} ]] \
&& sandbox_curl_with_exit "module-mgr/active" "&ids=${ARG_MODULE_ACTIVE}"
&& sandbox_curl_with_exit "sandbox-module-mgr/active" "&ids=${ARG_MODULE_ACTIVE}"

# -A frozen module
[[ ! -z ${OP_MODULE_FROZEN} ]] \
&& sandbox_curl_with_exit "module-mgr/frozen" "&ids=${ARG_MODULE_FROZEN}"
&& sandbox_curl_with_exit "sandbox-module-mgr/frozen" "&ids=${ARG_MODULE_FROZEN}"

# -m module detail
[[ ! -z ${OP_MODULE_DETAIL} ]] \
&& sandbox_curl_with_exit "module-mgr/detail" "&id=${ARG_MODULE_DETAIL}"
&& sandbox_curl_with_exit "sandbox-module-mgr/detail" "&id=${ARG_MODULE_DETAIL}"

# -S shutdown
[[ ! -z ${OP_SHUTDOWN} ]] \
&& sandbox_curl_with_exit "control/shutdown"
&& sandbox_curl_with_exit "sandbox-control/shutdown"

# -d debug
if [[ ! -z ${OP_DEBUG} ]]; then
Expand All @@ -352,7 +352,7 @@ function main() {
fi

# default
sandbox_curl "info/version"
sandbox_curl "sandbox-info/version"
exit

}
Expand Down
8 changes: 4 additions & 4 deletions doc/JVM-SANDBOX-USER-GUIDE-Chinese.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ EVENT_POOL_KEY_MAX : 2000
1. 必须实现`com.alibaba.jvm.sandbox.api.Module`接口
1. 必须完成`META-INF/services/com.alibaba.jvm.sandbox.api.Module`文件中的注册(Java SPI规范要求)

- 同一个JAR包所声明的所有模块共享同一个ModuleClassLoader
- 同一个JAR包所声明的所有模块共享同一个ModuleJarClassLoader

- 模块一共有四种状态

Expand Down Expand Up @@ -234,7 +234,7 @@ EVENT_POOL_KEY_MAX : 2000

- HTTP链接
- WEBSOCKET链接
- ModuleClassLoader
- ModuleJarClassLoader
- 待卸载模块引起的事件插桩

- `-f`
Expand All @@ -261,7 +261,7 @@ EVENT_POOL_KEY_MAX : 2000
- `-a`
激活模块,模块激活后才能受到沙箱事件
激活模块,模块激活后才能收到沙箱事件
- `-A`
Expand All @@ -283,7 +283,7 @@ EVENT_POOL_KEY_MAX : 2000
> STATE : FROZEN
> MODE : {AGENT,ATTACH}
> CLASS : class com.alibaba.jvm.sandbox.module.mgr.ModuleMgrModule
> LOADER : ModuleClassLoader[crc32=1721245995;file=/Users/luanjia/opt/sandbox/lib/../module/sandbox-mgr-module.jar;]
> LOADER : ModuleJarClassLoader[crc32=1721245995;file=/Users/luanjia/opt/sandbox/lib/../module/sandbox-mgr-module.jar;]
> cCnt : 0
> mCnt : 0
> ```
6 changes: 3 additions & 3 deletions doc/JVM-SANDBOX-USER-GUIDE-English.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Then the success of the start, the sandbox has been successfully implanted in th
2. You must implement the `com.alibaba.jvm.sandbox.api.Module` interface
3. You must complete the registration in the `META-INF / services / com.alibaba.jvm.sandbox.api.Module` file (Java SPI specification requirements)
- All modules declared in the same JAR package share the same ModuleClassLoader
- All modules declared in the same JAR package share the same ModuleJarClassLoader
- There are four states in the module
Expand Down Expand Up @@ -234,7 +234,7 @@ Then the success of the start, the sandbox has been successfully implanted in th
- HTTP link
- WEBSOCKET link
- ModuleClassLoader
- ModuleJarClassLoader
- The event is caused by the unloading of the module
- `-f`
Expand Down Expand Up @@ -283,7 +283,7 @@ Then the success of the start, the sandbox has been successfully implanted in th
> STATE : FROZEN
> MODE : {AGENT,ATTACH}
> CLASS : class com.alibaba.jvm.sandbox.module.mgr.ModuleMgrModule
> LOADER : ModuleClassLoader[crc32=1721245995;file=/Users/vlinux/opt/sandbox/lib/../module/sandbox-mgr-module.jar;]
> LOADER : ModuleJarClassLoader[crc32=1721245995;file=/Users/vlinux/opt/sandbox/lib/../module/sandbox-mgr-module.jar;]
> cCnt : 0
> mCnt : 0
> ```
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

<groupId>com.alibaba.jvm.sandbox</groupId>
<artifactId>sandbox</artifactId>
<version>1.1.2-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<packaging>pom</packaging>

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

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sandbox.version>1.1.2-SNAPSHOT</sandbox.version>
<sandbox.version>1.2.0-SNAPSHOT</sandbox.version>
</properties>

<build>
Expand Down
2 changes: 1 addition & 1 deletion sandbox-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alibaba.jvm.sandbox</groupId>
<artifactId>sandbox</artifactId>
<version>1.1.2-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
</parent>
<artifactId>sandbox-agent</artifactId>
<name>sandbox-agent ${sandbox.version}</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,14 @@
/**
* SandboxAgent启动器
* <ul>
* <li>这个类的所有静态属性都必须和版本、环境无关</li>
* <li>这个类删除、修改方法时必须考虑多版本情况下,兼容性问题!</li>
* <li>这个类的所有静态属性都必须和版本、环境无关</li>
* <li>这个类删除、修改方法时必须考虑多版本情况下,兼容性问题!</li>
* </ul>
*
* @author luanjia@taobao.com
*/
public class AgentLauncher {

// // sandbox配置文件目录
// private static final String SANDBOX_CFG_PATH
// = SANDBOX_HOME + File.separatorChar + "cfg";
//
// // 模块目录
// private static final String SANDBOX_MODULE_PATH
// = SANDBOX_HOME + File.separatorChar + "module";
//
//
// // sandbox核心工程文件
// private static final String SANDBOX_CORE_JAR_PATH
// = SANDBOX_HOME + File.separatorChar + "lib" + File.separator + "sandbox-core.jar";
//
// // sandbox-spy工程文件
// private static final String SANDBOX_SPY_JAR_PATH
// = SANDBOX_HOME + File.separatorChar + "lib" + File.separator + "sandbox-spy.jar";
//
// private static final String SANDBOX_PROPERTIES_PATH
// = SANDBOX_CFG_PATH + File.separator + "sandbox.properties";
//
// // sandbox-provider库目录
// private static final String SANDBOX_PROVIDER_LIB_PATH
// = SANDBOX_HOME + File.separatorChar + "provider";


private static String getSandboxCfgPath(String sandboxHome) {
return sandboxHome + File.separatorChar + "cfg";
}
Expand Down Expand Up @@ -114,7 +89,7 @@ private static String getSandboxProviderPath(String sandboxHome) {
*/
public static void premain(String featureString, Instrumentation inst) {
LAUNCH_MODE = LAUNCH_MODE_AGENT;
main(toFeatureMap(featureString), inst);
install(toFeatureMap(featureString), inst);
}

/**
Expand All @@ -130,7 +105,7 @@ public static void agentmain(String featureString, Instrumentation inst) {
writeAttachResult(
getNamespace(featureMap),
getToken(featureMap),
main(featureMap, inst)
install(featureMap, inst)
);
}

Expand Down Expand Up @@ -202,40 +177,37 @@ private static synchronized ClassLoader loadOrDefineClassLoader(final String nam
}

/**
* 获取当前命名空间下的ClassLoader
* <p>
* 该方法将会被{@code ControlModule#shutdown}通过反射调用,
* 请保持方法声明一致
* 删除指定命名空间下的jvm-sandbox
*
* @param namespace 命名空间
* @return 当前的ClassLoader
* @since {@code sandbox-api:1.0.15}
* @param namespace 指定命名空间
* @throws Throwable 删除失败
*/
@SuppressWarnings("unused")
public static ClassLoader getClassLoader(final String namespace) {
return sandboxClassLoaderMap.get(namespace);
public static synchronized void uninstall(final String namespace) throws Throwable {
final SandboxClassLoader sandboxClassLoader = sandboxClassLoaderMap.get(namespace);
if (null == sandboxClassLoader) {
return;
}

// 关闭服务器
final Class<?> classOfProxyServer = sandboxClassLoader.loadClass(CLASS_OF_PROXY_CORE_SERVER);
classOfProxyServer.getMethod("destroy")
.invoke(classOfProxyServer.getMethod("getInstance").invoke(null));

// 关闭SandboxClassLoader
sandboxClassLoader.closeIfPossible();
sandboxClassLoaderMap.remove(namespace);
}

/**
* 清理namespace所指定的ClassLoader
* <p>
* 该方法将会被{@code ControlModule#shutdown}通过反射调用,
* 请保持方法声明一致
* 在当前JVM安装jvm-sandbox
*
* @param namespace 命名空间
* @return 被清理的ClassLoader
* @param featureMap 启动参数配置
* @param inst inst
* @return 服务器IP:PORT
*/
@SuppressWarnings("unused")
public static synchronized ClassLoader cleanClassLoader(final String namespace) {
final SandboxClassLoader sandboxClassLoader = sandboxClassLoaderMap.remove(namespace);
if (null != sandboxClassLoader) {
sandboxClassLoader.closeIfPossible();
}
return sandboxClassLoader;
}

private static synchronized InetSocketAddress main(final Map<String, String> featureMap,
final Instrumentation inst) {
private static synchronized InetSocketAddress install(final Map<String, String> featureMap,
final Instrumentation inst) {

final String namespace = getNamespace(featureMap);
final String propertiesFilePath = getPropertiesFilePath(featureMap);
Expand All @@ -250,39 +222,39 @@ private static synchronized InetSocketAddress main(final Map<String, String> fea
)));

// 构造自定义的类加载器,尽量减少Sandbox对现有工程的侵蚀
final ClassLoader agentLoader = loadOrDefineClassLoader(
final ClassLoader sandboxClassLoader = loadOrDefineClassLoader(
namespace,
getSandboxCoreJarPath(getSandboxHome(featureMap))
// SANDBOX_CORE_JAR_PATH
);

// CoreConfigure类定义
final Class<?> classOfConfigure = agentLoader.loadClass(CLASS_OF_CORE_CONFIGURE);
final Class<?> classOfConfigure = sandboxClassLoader.loadClass(CLASS_OF_CORE_CONFIGURE);

// 反序列化成CoreConfigure类实例
final Object objectOfCoreConfigure = classOfConfigure.getMethod("toConfigure", String.class, String.class)
.invoke(null, coreFeatureString, propertiesFilePath);

// CoreServer类定义
final Class<?> classOfProxyServer = agentLoader.loadClass(CLASS_OF_PROXY_CORE_SERVER);
final Class<?> classOfProxyServer = sandboxClassLoader.loadClass(CLASS_OF_PROXY_CORE_SERVER);

// 获取CoreServer单例
final Object objectOfCoreServer = classOfProxyServer
final Object objectOfProxyServer = classOfProxyServer
.getMethod("getInstance")
.invoke(null);

// CoreServer.isBind()
final boolean isBind = (Boolean) classOfProxyServer.getMethod("isBind").invoke(objectOfCoreServer);
final boolean isBind = (Boolean) classOfProxyServer.getMethod("isBind").invoke(objectOfProxyServer);


// 如果未绑定,则需要绑定一个地址
if (!isBind) {
try {
classOfProxyServer
.getMethod("bind", classOfConfigure, Instrumentation.class)
.invoke(objectOfCoreServer, objectOfCoreConfigure, inst);
.invoke(objectOfProxyServer, objectOfCoreConfigure, inst);
} catch (Throwable t) {
classOfProxyServer.getMethod("destroy").invoke(objectOfCoreServer);
classOfProxyServer.getMethod("destroy").invoke(objectOfProxyServer);
throw t;
}

Expand All @@ -291,7 +263,7 @@ private static synchronized InetSocketAddress main(final Map<String, String> fea
// 返回服务器绑定的地址
return (InetSocketAddress) classOfProxyServer
.getMethod("getLocal")
.invoke(objectOfCoreServer);
.invoke(objectOfProxyServer);


} catch (Throwable cause) {
Expand Down
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 8557ef2

Please sign in to comment.