comparison test/runtime/RedefineObject/Agent.java @ 10268:43083e670adf

8005056: NPG: Crash after redefining java.lang.Object Summary: Need to walk array class vtables replacing old methods too if j.l.o redefined Reviewed-by: sspitsyn, dcubed, ctornqvi
author coleenp
date Mon, 13 May 2013 15:37:08 -0400
parents
children 85147f28faba
comparison
equal deleted inserted replaced
10267:8b40495b9381 10268:43083e670adf
1 /*
2 * Copyright (c) 2013, 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 */
23 import java.security.*;
24 import java.lang.instrument.*;
25
26 public class Agent implements ClassFileTransformer {
27 public synchronized byte[] transform(final ClassLoader classLoader,
28 final String className,
29 Class<?> classBeingRedefined,
30 ProtectionDomain protectionDomain,
31 byte[] classfileBuffer) {
32 //System.out.println("Transforming class " + className);
33 return classfileBuffer;
34 }
35
36 public static void premain(String agentArgs, Instrumentation instrumentation) {
37
38 Agent transformer = new Agent();
39
40 instrumentation.addTransformer(transformer, true);
41
42 Class c = Object.class;
43 try {
44 instrumentation.retransformClasses(c);
45 } catch (Exception e) {
46 e.printStackTrace();
47 }
48
49 instrumentation.removeTransformer(transformer);
50 }
51
52 public static void main(String[] args) {
53 byte[] ba = new byte[0];
54
55 // If it survives 1000 GC's, it's good.
56 for (int i = 0; i < 1000 ; i++) {
57 System.gc();
58 ba.clone();
59 }
60 }
61 }