01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.object.ibm;
06:
07: import com.tc.asm.ClassAdapter;
08: import com.tc.asm.ClassVisitor;
09: import com.tc.asm.MethodAdapter;
10: import com.tc.asm.MethodVisitor;
11: import com.tc.asm.Opcodes;
12: import com.tc.object.bytecode.ClassAdapterFactory;
13:
14: public class SystemInitializationAdapter extends ClassAdapter implements
15: ClassAdapterFactory {
16:
17: public SystemInitializationAdapter(ClassVisitor cv) {
18: super (cv);
19: }
20:
21: public SystemInitializationAdapter() {
22: super (null);
23: }
24:
25: public MethodVisitor visitMethod(int access, String name,
26: String desc, String signature, String[] exceptions) {
27: MethodVisitor mv = super .visitMethod(access, name, desc,
28: signature, exceptions);
29:
30: if ("lastChanceHook".equals(name)) {
31: return new LastChanceHookAdapter(mv);
32: }
33:
34: return mv;
35:
36: }
37:
38: private static class LastChanceHookAdapter extends MethodAdapter
39: implements Opcodes {
40:
41: public LastChanceHookAdapter(MethodVisitor mv) {
42: super (mv);
43: }
44:
45: public void visitMethodInsn(int opcode, String owner,
46: String name, String desc) {
47: super .visitMethodInsn(opcode, owner, name, desc);
48:
49: // The important bit with this particular location is that it happens
50: // before the jmx remote agent thread is started
51: if ((opcode == INVOKESTATIC)
52: && "getProperties".equals(name)
53: && "java/lang/System".equals(owner)) {
54: super
55: .visitMethodInsn(
56: INVOKESTATIC,
57: "com/tc/object/bytecode/hook/impl/ClassProcessorHelper",
58: "init", "()V");
59: }
60: }
61: }
62:
63: public ClassAdapter create(ClassVisitor visitor, ClassLoader loader) {
64: return new SystemInitializationAdapter(visitor);
65: }
66:
67: }
|