JDK-8020357.js revision 445:965d876853ec
1181847Sjkim/* 2182393Sjkim * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3181847Sjkim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4181847Sjkim * 5181847Sjkim * This code is free software; you can redistribute it and/or modify it 6181847Sjkim * under the terms of the GNU General Public License version 2 only, as 7181847Sjkim * published by the Free Software Foundation. 8181847Sjkim * 9182393Sjkim * This code is distributed in the hope that it will be useful, but WITHOUT 10182393Sjkim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11181847Sjkim * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12181847Sjkim * version 2 for more details (a copy is included in the LICENSE file that 13181847Sjkim * accompanied this code). 14181847Sjkim * 15181847Sjkim * You should have received a copy of the GNU General Public License version 16181847Sjkim * 2 along with this work; if not, write to the Free Software Foundation, 17181847Sjkim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18181847Sjkim * 19181847Sjkim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20181847Sjkim * or visit www.oracle.com if you need additional information or have any 21181847Sjkim * questions. 22181847Sjkim */ 23181847Sjkim 24181847Sjkim/** 25181847Sjkim * JDK-8020357: Return range error for too big native array buffers 26181847Sjkim * 27181847Sjkim * @test 28181847Sjkim * @run 29181847Sjkim */ 30181847Sjkim 31182393Sjkimvar UNSIGNED_INT_BITS = 31 32181847Sjkimvar BYTES_PER_INT_32 = 4 33 34var limit = Math.pow(2, UNSIGNED_INT_BITS)/BYTES_PER_INT_32 35 36try { 37 // A value at or under the limit should either succeed if we have 38 // enough heap, or throw an OutOfMemoryError if we don't. 39 Int32Array(limit - 1) 40} catch(e) { 41 if(!(e instanceof java.lang.OutOfMemoryError)) { 42 // Only print an unexpected result; OutOfMemoryError is expected 43 print(e) 44 } 45} 46 47// A value over the limit should throw a RangeError. 48try { 49 Int32Array(limit) 50} catch(e) { 51 print(e) 52} 53