jdk/test/java/lang/instrument/ManyMethodsBenchmarkAgent.java
author sspitsyn
Wed, 25 Feb 2015 01:02:04 -0800
changeset 29383 971ae566f595
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale Summary: add new test java/lang/instrument/ManyMethodsBenchmarkAgent.java Reviewed-by: coleenp, dcubed Contributed-by: serguei.spitsyn@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29383
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
     1
/*
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
     4
 *
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
     8
 *
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    13
 * accompanied this code).
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    14
 *
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    18
 *
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    21
 * questions.
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    22
 */
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    23
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    24
/**
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    25
 * @test
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    26
 * @bug 8046246
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    27
 * @summary Tests and benchmarks the JVMTI RedefineClasses when a
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    28
 *          single class (and its parent) contains many methods.
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    29
 *
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    30
 * @run build ManyMethodsBenchmarkApp ManyMethodsBenchmarkAgent
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    31
 * @run shell MakeJAR3.sh ManyMethodsBenchmarkAgent 'Can-Retransform-Classes: true'
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    32
 * @run main/othervm -javaagent:ManyMethodsBenchmarkAgent.jar ManyMethodsBenchmarkApp
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    33
 */
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    34
import java.lang.instrument.*;
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    35
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    36
public class ManyMethodsBenchmarkAgent
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    37
{
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    38
    public  static boolean fail = false;
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    39
    public  static boolean completed = false;
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    40
    private static  Instrumentation instrumentation;
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    41
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    42
    public static void
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    43
    premain(    String agentArgs,
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    44
                Instrumentation instrumentation) {
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    45
        System.out.println("ManyMethodsBenchmarkAgent started");
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    46
        ManyMethodsBenchmarkAgent.instrumentation = instrumentation;
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    47
        System.out.println("ManyMethodsBenchmarkAgent finished");
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    48
    }
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    49
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    50
    static void instr() {
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    51
        System.out.println("ManyMethodsBenchmarkAgent.instr started");
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    52
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    53
        Class[] allClasses = instrumentation.getAllLoadedClasses();
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    54
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    55
        for (int i = 0; i < allClasses.length; i++) {
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    56
            Class klass = allClasses[i];
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    57
            String name = klass.getName();
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    58
            if (!name.equals("Base")) {
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    59
                continue;
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    60
            }
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    61
            System.err.println("Instrumenting the class: " + klass);
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    62
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    63
            try {
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    64
                instrumentation.retransformClasses(klass);
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    65
            } catch (Throwable e) {
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    66
                System.err.println("Error: bad return from retransform: " + klass);
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    67
                System.err.println("  ERROR: " + e);
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    68
                fail = true;
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    69
            }
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    70
        }
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    71
        completed = true;
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    72
        System.out.println("ManyMethodsBenchmarkAgent.instr finished");
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    73
    }
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    74
971ae566f595 8046246: the constantPoolCacheOopDesc::adjust_method_entries() used in RedefineClasses does not scale
sspitsyn
parents:
diff changeset
    75
}