hotspot/test/runtime/SharedArchiveFile/SASymbolTableTestAgent.java
author goetz
Thu, 03 Aug 2017 10:24:34 +0200
changeset 46779 d80ca591ae48
parent 41340 64703e04389c
permissions -rw-r--r--
8185436: jtreg: introduce @requires property to disable cds tests Summary: Fix CompressedClassPointers test to succeed also if cds is not available. Reviewed-by: jiangli, mseledtsov, iklam
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
     1
/*
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
     4
 *
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
     8
 *
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    13
 * accompanied this code).
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    14
 *
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    18
 *
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    21
 * questions.
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    22
 */
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    23
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    24
import sun.jvm.hotspot.memory.SymbolTable;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    25
import sun.jvm.hotspot.oops.Symbol;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    26
import sun.jvm.hotspot.runtime.VM;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    27
import sun.jvm.hotspot.tools.Tool;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    28
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    29
/**
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    30
 * This class is launched in a sub-process by the main test,
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    31
 * SASymbolTableTest.java.
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    32
 *
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    33
 * It uses SA to connect to another JVM process, whose PID is specified in args[].
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    34
 * The purpose of the test is to validate that we can walk the SymbolTable
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    35
 * and CompactHashTable of the other process. Everything should work regardless
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    36
 * of whether the other process runs in CDS mode or not.
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    37
 *
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    38
 * Note: CompactHashTable is used only when CDS is enabled.
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    39
 */
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    40
public class SASymbolTableTestAgent extends Tool {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    41
    public SASymbolTableTestAgent() {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    42
        super();
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    43
    }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    44
    public static void main(String args[]) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    45
        SASymbolTableTestAgent tool = new SASymbolTableTestAgent();
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    46
        tool.execute(args);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    47
    }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    48
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    49
    static String[] commonNames = {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    50
        "java/lang/Object",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    51
        "java/lang/String",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    52
        "java/lang/Class",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    53
        "java/lang/Cloneable",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    54
        "java/lang/ClassLoader",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    55
        "java/io/Serializable",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    56
        "java/lang/System",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    57
        "java/lang/Throwable",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    58
        "java/lang/Error",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    59
        "java/lang/ThreadDeath",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    60
        "java/lang/Exception",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    61
        "java/lang/RuntimeException",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    62
        "java/lang/SecurityManager",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    63
        "java/security/ProtectionDomain",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    64
        "java/security/AccessControlContext",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    65
        "java/security/SecureClassLoader",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    66
        "java/lang/ClassNotFoundException",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    67
        "java/lang/NoClassDefFoundError",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    68
        "java/lang/LinkageError",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    69
        "java/lang/ClassCastException",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    70
        "java/lang/ArrayStoreException",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    71
        "java/lang/VirtualMachineError",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    72
        "java/lang/OutOfMemoryError",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    73
        "java/lang/StackOverflowError",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    74
        "java/lang/IllegalMonitorStateException",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    75
        "java/lang/ref/Reference",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    76
        "java/lang/ref/SoftReference",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    77
        "java/lang/ref/WeakReference",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    78
        "java/lang/ref/FinalReference",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    79
        "java/lang/ref/PhantomReference",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    80
        "java/lang/ref/Finalizer",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    81
        "java/lang/Thread",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    82
        "java/lang/ThreadGroup",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    83
        "java/util/Properties",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    84
        "java/lang/reflect/AccessibleObject",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    85
        "java/lang/reflect/Field",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    86
        "java/lang/reflect/Method",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    87
        "java/lang/reflect/Constructor",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    88
        "java/lang/invoke/MethodHandle",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    89
        "java/lang/invoke/MemberName",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    90
        "java/lang/invoke/MethodHandleNatives",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    91
        "java/lang/invoke/MethodType",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    92
        "java/lang/BootstrapMethodError",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    93
        "java/lang/invoke/CallSite",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    94
        "java/lang/invoke/ConstantCallSite",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    95
        "java/lang/invoke/MutableCallSite",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    96
        "java/lang/invoke/VolatileCallSite",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    97
        "java/lang/StringBuffer",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    98
        "java/lang/StringBuilder",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
    99
        "java/io/ByteArrayInputStream",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   100
        "java/io/File",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   101
        "java/net/URLClassLoader",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   102
        "java/net/URL",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   103
        "java/util/jar/Manifest",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   104
        "java/security/CodeSource",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   105
    };
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   106
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   107
    static String[] badNames = {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   108
        "java/lang/badbadbad",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   109
        "java/io/badbadbadbad",
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   110
        "this*symbol*must*not*exist"
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   111
    };
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   112
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   113
    public void run() {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   114
        System.out.println("SASymbolTableTestAgent: starting");
41340
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   115
        try {
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   116
            VM vm = VM.getVM();
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   117
            SymbolTable table = vm.getSymbolTable();
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   118
41340
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   119
            // (a) These are names that are likely to exist in the symbol table
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   120
            //     of a JVM after start-up. They were taken from vmSymbols.hpp
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   121
            //     during the middle of JDK9 development.
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   122
            //
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   123
            //     The purpose is not to check that each name must exist (a future
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   124
            //     version of JDK may not preload some of the classes).
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   125
            //
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   126
            //     The purpose of this loops is to ensure that we check a lot of symbols,
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   127
            //     so we will (most likely) hit on both VALUE_ONLY_BUCKET_TYPE and normal bucket type
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   128
            //     in CompactHashTable.probe().
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   129
            for (String n : commonNames) {
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   130
                Symbol s = table.probe(n);
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   131
                System.out.format("%-40s = %s\n", n, s);
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   132
            }
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   133
41340
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   134
            System.out.println("======================================================================");
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   135
41340
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   136
            // (b) Also test a few strings that are known to not exist in the table. This will
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   137
            //     both the compact table (if it exists) and the regular table to be walked.
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   138
            for (String n : badNames) {
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   139
                Symbol s = table.probe(n);
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   140
                System.out.format("%-40s = %s\n", n, s);
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   141
            }
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   142
        } catch (NullPointerException e) {
64703e04389c 8165537: runtime/SharedArchiveFile/SASymbolTableTest.java fails with NullPointerException
vtewari
parents: 37995
diff changeset
   143
            System.out.println("connected too early -- please try again");
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   144
        }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   145
    }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents:
diff changeset
   146
}