test/serviceability/jvmti/GetObjectSizeOverflow.java

Thu, 22 May 2014 09:12:29 +0200

author
allwin
date
Thu, 22 May 2014 09:12:29 +0200
changeset 6689
997fd9660dd5
child 6717
09f19d3de485
permissions
-rw-r--r--

8027230: Overflow in java.lang.instrument.Instrumentation.getObjectSize() method
Reviewed-by: dholmes, sspitsyn

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

mercurial