test/runtime/RedefineObject/Agent.java

Thu, 18 Jul 2013 03:38:10 -0700

author
cl
date
Thu, 18 Jul 2013 03:38:10 -0700
changeset 5396
bb416ee2a79b
parent 5100
43083e670adf
child 5508
85147f28faba
permissions
-rw-r--r--

Added tag jdk8-b99 for changeset 81b6cb70717c

coleenp@5100 1 /*
coleenp@5100 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
coleenp@5100 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
coleenp@5100 4 *
coleenp@5100 5 * This code is free software; you can redistribute it and/or modify it
coleenp@5100 6 * under the terms of the GNU General Public License version 2 only, as
coleenp@5100 7 * published by the Free Software Foundation.
coleenp@5100 8 *
coleenp@5100 9 * This code is distributed in the hope that it will be useful, but WITHOUT
coleenp@5100 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
coleenp@5100 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
coleenp@5100 12 * version 2 for more details (a copy is included in the LICENSE file that
coleenp@5100 13 * accompanied this code).
coleenp@5100 14 *
coleenp@5100 15 * You should have received a copy of the GNU General Public License version
coleenp@5100 16 * 2 along with this work; if not, write to the Free Software Foundation,
coleenp@5100 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
coleenp@5100 18 *
coleenp@5100 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
coleenp@5100 20 * or visit www.oracle.com if you need additional information or have any
coleenp@5100 21 * questions.
coleenp@5100 22 */
coleenp@5100 23 import java.security.*;
coleenp@5100 24 import java.lang.instrument.*;
coleenp@5100 25
coleenp@5100 26 public class Agent implements ClassFileTransformer {
coleenp@5100 27 public synchronized byte[] transform(final ClassLoader classLoader,
coleenp@5100 28 final String className,
coleenp@5100 29 Class<?> classBeingRedefined,
coleenp@5100 30 ProtectionDomain protectionDomain,
coleenp@5100 31 byte[] classfileBuffer) {
coleenp@5100 32 //System.out.println("Transforming class " + className);
coleenp@5100 33 return classfileBuffer;
coleenp@5100 34 }
coleenp@5100 35
coleenp@5100 36 public static void premain(String agentArgs, Instrumentation instrumentation) {
coleenp@5100 37
coleenp@5100 38 Agent transformer = new Agent();
coleenp@5100 39
coleenp@5100 40 instrumentation.addTransformer(transformer, true);
coleenp@5100 41
coleenp@5100 42 Class c = Object.class;
coleenp@5100 43 try {
coleenp@5100 44 instrumentation.retransformClasses(c);
coleenp@5100 45 } catch (Exception e) {
coleenp@5100 46 e.printStackTrace();
coleenp@5100 47 }
coleenp@5100 48
coleenp@5100 49 instrumentation.removeTransformer(transformer);
coleenp@5100 50 }
coleenp@5100 51
coleenp@5100 52 public static void main(String[] args) {
coleenp@5100 53 byte[] ba = new byte[0];
coleenp@5100 54
coleenp@5100 55 // If it survives 1000 GC's, it's good.
coleenp@5100 56 for (int i = 0; i < 1000 ; i++) {
coleenp@5100 57 System.gc();
coleenp@5100 58 ba.clone();
coleenp@5100 59 }
coleenp@5100 60 }
coleenp@5100 61 }

mercurial