1 /*
2 * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
82 * @return a random transformer
83 */
84 protected ClassFileTransformer
85 getRandomTransformer()
86 {
87 int randIndex = (int)Math.floor(Math.random() * kTransformerSamples.length);
88 verbosePrint("Choosing random transformer #" + randIndex);
89 return kTransformerSamples[randIndex];
90 }
91
92 /**
93 * Method addTransformerToManager.
94 * @param manager
95 * @param transformer
96 */
97 protected void
98 addTransformerToManager(
99 Instrumentation manager,
100 ClassFileTransformer transformer)
101 {
102 if (transformer != null)
103 {
104 fTransformers.add(transformer);
105 }
106 manager.addTransformer(transformer);
107 verbosePrint("Added transformer " + transformer);
108 }
109
110 /**
111 * Remove transformer from manager and list
112 * @param manager
113 * @param transformer
114 */
115 protected void
116 removeTransformerFromManager(
117 Instrumentation manager,
118 ClassFileTransformer transformer)
119 {
120 assertTrue("Transformer not found in manager ("+transformer+")", manager.removeTransformer(transformer));
121
122 if (transformer != null)
123 {
124 fTransformers.remove(transformer);
125 }
126 verbosePrint("Removed transformer " + transformer);
127 }
|
1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
82 * @return a random transformer
83 */
84 protected ClassFileTransformer
85 getRandomTransformer()
86 {
87 int randIndex = (int)Math.floor(Math.random() * kTransformerSamples.length);
88 verbosePrint("Choosing random transformer #" + randIndex);
89 return kTransformerSamples[randIndex];
90 }
91
92 /**
93 * Method addTransformerToManager.
94 * @param manager
95 * @param transformer
96 */
97 protected void
98 addTransformerToManager(
99 Instrumentation manager,
100 ClassFileTransformer transformer)
101 {
102 addTransformerToManager(manager, transformer, false);
103 }
104
105 /**
106 * Method addTransformerToManager.
107 * @param manager
108 * @param transformer
109 * @param canRetransform
110 */
111 protected void
112 addTransformerToManager(
113 Instrumentation manager,
114 ClassFileTransformer transformer,
115 boolean canRetransform)
116 {
117 if (transformer != null)
118 {
119 fTransformers.add(transformer);
120 }
121 manager.addTransformer(transformer, canRetransform);
122 verbosePrint("Added transformer " + transformer
123 + " with canRetransform=" + canRetransform);
124 }
125
126 /**
127 * Remove transformer from manager and list
128 * @param manager
129 * @param transformer
130 */
131 protected void
132 removeTransformerFromManager(
133 Instrumentation manager,
134 ClassFileTransformer transformer)
135 {
136 assertTrue("Transformer not found in manager ("+transformer+")", manager.removeTransformer(transformer));
137
138 if (transformer != null)
139 {
140 fTransformers.remove(transformer);
141 }
142 verbosePrint("Removed transformer " + transformer);
143 }
|