test/runtime/NMT/UnsafeMallocLimit.java

Thu, 04 Sep 2014 14:50:31 -0400

author
zgu
date
Thu, 04 Sep 2014 14:50:31 -0400
changeset 7177
ed3d653e4012
permissions
-rw-r--r--

8055289: Internal Error: mallocTracker.cpp:146 fatal error: Should not use malloc for big memory block, use virtual memory instead
Summary: Return NULL if memory allocation size is bigger than MAX_MALLOC_SIZE when NMT is on
Reviewed-by: coleenp, gtriantafill

zgu@7177 1 /*
zgu@7177 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
zgu@7177 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
zgu@7177 4 *
zgu@7177 5 * This code is free software; you can redistribute it and/or modify it
zgu@7177 6 * under the terms of the GNU General Public License version 2 only, as
zgu@7177 7 * published by the Free Software Foundation.
zgu@7177 8 *
zgu@7177 9 * This code is distributed in the hope that it will be useful, but WITHOUT
zgu@7177 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
zgu@7177 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
zgu@7177 12 * version 2 for more details (a copy is included in the LICENSE file that
zgu@7177 13 * accompanied this code).
zgu@7177 14 *
zgu@7177 15 * You should have received a copy of the GNU General Public License version
zgu@7177 16 * 2 along with this work; if not, write to the Free Software Foundation,
zgu@7177 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
zgu@7177 18 *
zgu@7177 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
zgu@7177 20 * or visit www.oracle.com if you need additional information or have any
zgu@7177 21 * questions.
zgu@7177 22 */
zgu@7177 23
zgu@7177 24 /*
zgu@7177 25 * @test
zgu@7177 26 * @bug 8055289
zgu@7177 27 * @library /testlibrary
zgu@7177 28 * @build UnsafeMallocLimit
zgu@7177 29 * @run main/othervm -Xmx32m -XX:NativeMemoryTracking=summary UnsafeMallocLimit
zgu@7177 30 */
zgu@7177 31
zgu@7177 32 import com.oracle.java.testlibrary.*;
zgu@7177 33 import sun.misc.Unsafe;
zgu@7177 34
zgu@7177 35 public class UnsafeMallocLimit {
zgu@7177 36
zgu@7177 37 public static void main(String args[]) throws Exception {
zgu@7177 38 if (Platform.is32bit()) {
zgu@7177 39 Unsafe unsafe = Utils.getUnsafe();
zgu@7177 40 try {
zgu@7177 41 unsafe.allocateMemory(1 << 30);
zgu@7177 42 throw new RuntimeException("Did not get expected OOME");
zgu@7177 43 } catch (OutOfMemoryError e) {
zgu@7177 44 // Expected exception
zgu@7177 45 }
zgu@7177 46 } else {
zgu@7177 47 System.out.println("Test only valid on 32-bit platforms");
zgu@7177 48 }
zgu@7177 49 }
zgu@7177 50 }

mercurial