hotspot/test/serviceability/jvmti/GetObjectSizeOverflow.java
author jwilhelm
Thu, 26 Feb 2015 21:00:03 +0100
changeset 29324 8672c9d7ae94
parent 24835 be963975e2f7
child 29678 dd2f3932c21e
permissions -rw-r--r--
8073883: serviceability/dcmd/gc/RunGCTest.java should not run with -XX:+ExplicitGCInvokesConcurrent Summary: Don't run test with -XX:+ExplicitGCInvokesConcurrent Reviewed-by: mgerdin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24659
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
     1
/*
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
     2
 * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
     4
 *
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
     8
 *
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    13
 * accompanied this code).
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    14
 *
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    18
 *
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    21
 * questions.
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    22
 */
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    23
import java.io.PrintWriter;
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    24
import com.oracle.java.testlibrary.*;
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    25
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    26
/*
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    27
 * Test to verify GetObjectSize does not overflow on a 600M element int[]
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    28
 *
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    29
 * @test
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    30
 * @bug 8027230
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    31
 * @library /testlibrary
24835
be963975e2f7 8043915: Tests get ClassNotFoundException: com.oracle.java.testlibrary.StreamPumper
ykantser
parents: 24659
diff changeset
    32
 * @build ClassFileInstaller com.oracle.java.testlibrary.* GetObjectSizeOverflowAgent
24659
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    33
 * @run main ClassFileInstaller GetObjectSizeOverflowAgent
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    34
 * @run main GetObjectSizeOverflow
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    35
 */
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    36
public class GetObjectSizeOverflow {
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    37
    public static void main(String[] args) throws Exception  {
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    38
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    39
        if (!Platform.is64bit()) {
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    40
            System.out.println("Test needs a 4GB heap and can only be run as a 64bit process, skipping.");
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    41
            return;
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    42
        }
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    43
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    44
        PrintWriter pw = new PrintWriter("MANIFEST.MF");
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    45
        pw.println("Premain-Class: GetObjectSizeOverflowAgent");
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    46
        pw.close();
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    47
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    48
        ProcessBuilder pb = new ProcessBuilder();
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    49
        pb.command(new String[] { JDKToolFinder.getJDKTool("jar"), "cmf", "MANIFEST.MF", "agent.jar", "GetObjectSizeOverflowAgent.class"});
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    50
        pb.start().waitFor();
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    51
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    52
        ProcessBuilder pt = ProcessTools.createJavaProcessBuilder(true, "-Xmx4000m", "-javaagent:agent.jar",  "GetObjectSizeOverflowAgent");
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    53
        OutputAnalyzer output = new OutputAnalyzer(pt.start());
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    54
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    55
        if (output.getStdout().contains("Could not reserve enough space") || output.getStderr().contains("java.lang.OutOfMemoryError")) {
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    56
            System.out.println("stdout: " + output.getStdout());
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    57
            System.out.println("stderr: " + output.getStderr());
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    58
            System.out.println("Test could not reserve or allocate enough space, skipping");
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    59
            return;
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    60
        }
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    61
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    62
        output.stdoutShouldContain("GetObjectSizeOverflow passed");
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    63
    }
a1482c33e323 8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
allwin
parents:
diff changeset
    64
}