本文整理汇总了Java中com.heliosapm.shorthand.attach.vm.agent.LocalAgentInstaller类的典型用法代码示例。如果您正苦于以下问题:Java LocalAgentInstaller类的具体用法?Java LocalAgentInstaller怎么用?Java LocalAgentInstaller使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocalAgentInstaller类属于com.heliosapm.shorthand.attach.vm.agent包,在下文中一共展示了LocalAgentInstaller类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initInstr
import com.heliosapm.shorthand.attach.vm.agent.LocalAgentInstaller; //导入依赖的package包/类
static void initInstr() {
final Instrumentation instr = LocalAgentInstaller.getInstrumentation();
// final Transformer tran = new Transformer(new MethodDatabase(TestCont.class.getClassLoader()), false);
final QTransformer tran = new QTransformer(new QuasarInstrumentor(Test.class.getClassLoader()));
instr.addTransformer(tran, true);
try {
instr.retransformClasses(
MBeanServerConnection.class,
MBeanServerConnectionAsync.class,
SR.class,
// TaskFiber.class,
Test.class,
MBeanServerConnectionAsync.class,
SuspendableMBeanServerConnection.class);
log("Classes transformed");
} catch (Exception ex) {
ex.printStackTrace(System.err);
throw new RuntimeException(ex);
} finally {
instr.removeTransformer(tran);
}
}
示例2: main
import com.heliosapm.shorthand.attach.vm.agent.LocalAgentInstaller; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
log("TestBulk");
JMXHelper.fireUpJMXMPServer("0.0.0.0", 7774, JMXHelper.getHeliosMBeanServer());
ExtendedThreadManager.install();
JavaAgent.premain("", LocalAgentInstaller.getInstrumentation());
System.setProperty("co.paralleluniverse.fibers.verifyInstrumentation", "true");
//initInstr();
try {
final MBeanServerConnection conn = JMXConnectorFactory.connect(new JMXServiceURL("service:jmx:jmxmp://localhost:7774")).getMBeanServerConnection();
final JMXBulkServiceMBean bulkService = MBeanServerInvocationHandler.newProxyInstance(conn, BULK, JMXBulkServiceMBean.class, false);
JMXHelper.registerMBean(BULK, new JMXBulkService());
final BulkInvocationBuilder bib = new BulkInvocationBuilder(true, 8192, conn);
final MBeanServerConnection msc = new SuspendableMBeanServerConnection(bib);
// new SR(msc).start();//.join();
//msc.queryNames(new ObjectName("*:*"), null);
// SystemClock.sleep(2000);
// final HomeBulkInvocation home = bib.build();
// log("Home: %s", home);
// BulkResponse br = bulkService.invoke(home);
// log("Response: %s", br);
fiberGoAhead(msc);
} catch (Exception ex) {
ex.printStackTrace(System.err);
}
}
示例3: main
import com.heliosapm.shorthand.attach.vm.agent.LocalAgentInstaller; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
log("Instrumenting InstrumentationPrototype.normalOp");
final Instrumentation instr = LocalAgentInstaller.getInstrumentation();
final byte[] byteCode = getByteCode(instr, InstrumentationPrototype.class);
ClassReader classReader = new ClassReader(byteCode);
ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_MAXS);
final Map<String, String[]> targetMethods = new HashMap<String, String[]>();
getMethod(targetMethods, InstrumentationPrototype.class, "instrumentedOp", String.class);
ClassIntrumentor ci = new ClassIntrumentor(classWriter, targetMethods);
classReader.accept(ci, 0);
Map<String, byte[]> bc = Collections.singletonMap(InstrumentationPrototype.class.getName().replace('.', '/'), classWriter.toByteArray());
retransform(instr, bc, InstrumentationPrototype.class);
}
示例4: ShorthandCompiler
import com.heliosapm.shorthand.attach.vm.agent.LocalAgentInstaller; //导入依赖的package包/类
private ShorthandCompiler() {
try {
defineClassMethod = ClassLoader.class.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class, ProtectionDomain.class);
defineClassMethod.setAccessible(true);
instrumentation = LocalAgentInstaller.getInstrumentation();
iDataMapperCtClass = classPool.get(IDataMapper.class.getName());
atomicBooleanCtClass = classPool.get(AtomicBoolean.class.getName());
stringCtClass = classPool.get(String.class.getName());
metricNameProviderCtClass = classPool.get(MetricNameProvider.class.getName());
staticInterceptorCtClass = classPool.get(ShorthandStaticInterceptor.class.getName());
throwableCtClass = classPool.get(Throwable.class.getName());
longArrClass = classPool.get(long[].class.getName());
threadLocalCtClass = classPool.get(ThreadLocal.class.getName());
nonBlockingHashMapLongCtClass = classPool.get(NonBlockingHashMapLong.class.getName());
nonBlockingHashMapCtClass = classPool.get(NonBlockingHashMap.class.getName());
classPool.appendClassPath(new ClassClassPath(UnsafeAdapter.class));
classPool.importPackage("com.heliosapm.shorthand.util.unsafe");
classPool.importPackage("java.util");
classPool.importPackage(NonBlockingHashMap.class.getPackage().getName());
classPool.importPackage(DataMapperBuilder.class.getPackage().getName());
classPool.importPackage(ShorthandStaticInterceptor.class.getPackage().getName());
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
示例5: wrap
import com.heliosapm.shorthand.attach.vm.agent.LocalAgentInstaller; //导入依赖的package包/类
public void wrap(Method method) {
log("Wrapping [%s]", method.toGenericString());
Member member = method;
log("Signature [%s]", StringHelper.getMemberDescriptor(member));
try {
Class<?> clazz = method.getDeclaringClass();
CtClass ctClazz = classPool.get(clazz.getName());
CtClass[] ctParams = new CtClass[method.getParameterTypes().length];
for(int i = 0; i < ctParams.length; i++) {
ctParams[i] = classPool.get(method.getParameterTypes()[i].getName());
}
log("Instrumenting [%s]", Descriptor.ofParameters(ctParams));
CtMethod ctMethod = ctClazz.getDeclaredMethod(method.getName(), ctParams);
Handler lastThrowable = getLastHandler(ctMethod, false);
log("Last Throwable Handler [%s]", lastThrowable);
ctMethod.insertBefore("System.out.println(\"MethodEnter[\" + Arrays.toString($args) + \"]\");");
ctMethod.insertAfter("System.out.println(\"MethodExit[\" + Arrays.toString($args) + \"]\");");
// com.heliosapm.shorthand.util.unsafe.UnsafeAdapter
ctMethod.addCatch("System.out.println(\"MethodError[\" + Arrays.toString($args) + \"]\"); UnsafeAdapter.throwException($e); throw new RuntimeException();", throwableCtClass, "$e");
final String targetName = clazz.getName().replace('.', '/');
final byte[] byteCode = ctClazz.toBytecode();
ctClazz.writeFile(JS_DEBUG);
ClassFileTransformer cft = new ClassFileTransformer() {
/**
* {@inheritDoc}
* @see java.lang.instrument.ClassFileTransformer#transform(java.lang.ClassLoader, java.lang.String, java.lang.Class, java.security.ProtectionDomain, byte[])
*/
@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
if(className.equals(targetName)) return byteCode;
return classfileBuffer;
}
};
Instrumentation instr = LocalAgentInstaller.getInstrumentation();
instr.addTransformer(cft, false);
instr.retransformClasses(clazz);
instr.removeTransformer(cft);
log("Transformed class [%s]", clazz.getName());
} catch (Exception ex) {
ex.printStackTrace(System.err);
}
}
示例6: BodyWrapTest
import com.heliosapm.shorthand.attach.vm.agent.LocalAgentInstaller; //导入依赖的package包/类
/**
* Creates a new BodyWrapTest
*/
public BodyWrapTest() {
log("BodyWrapTest");
instr = LocalAgentInstaller.getInstrumentation();
log("Instrumentation [%s]", instr);
}