hannesw@1557: /* hannesw@1557: * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. hannesw@1557: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. hannesw@1557: * hannesw@1557: * This code is free software; you can redistribute it and/or modify it hannesw@1557: * under the terms of the GNU General Public License version 2 only, as hannesw@1557: * published by the Free Software Foundation. hannesw@1557: * hannesw@1557: * This code is distributed in the hope that it will be useful, but WITHOUT hannesw@1557: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or hannesw@1557: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License hannesw@1557: * version 2 for more details (a copy is included in the LICENSE file that hannesw@1557: * accompanied this code). hannesw@1557: * hannesw@1557: * You should have received a copy of the GNU General Public License version hannesw@1557: * 2 along with this work; if not, write to the Free Software Foundation, hannesw@1557: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. hannesw@1557: * hannesw@1557: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA hannesw@1557: * or visit www.oracle.com if you need additional information or have any hannesw@1557: * questions. hannesw@1557: */ hannesw@1557: hannesw@1557: /** hannesw@1557: * JDK-8137281: OutOfMemoryError with large numeric keys in JSON.parse hannesw@1557: * hannesw@1557: * @test hannesw@1557: * @run hannesw@1557: */ hannesw@1557: hannesw@1557: function createObject(startKey, level1, level2) { hannesw@1557: var root = {}; hannesw@1557: var key = startKey; hannesw@1557: for (var i = 0; i < level1; i++) { hannesw@1557: var child = {}; hannesw@1557: for (var j = 0; j < level2; j++) { hannesw@1557: child[key++] = {}; hannesw@1557: } hannesw@1557: root[key++] = child; hannesw@1557: } hannesw@1557: return root; hannesw@1557: } hannesw@1557: hannesw@1557: JSON.parse(JSON.stringify(createObject(500000, 20, 20))); hannesw@1557: JSON.parse(JSON.stringify(createObject(1000000, 20, 20))); hannesw@1557: JSON.parse(JSON.stringify(createObject(2000000, 20, 20))); hannesw@1557: JSON.parse(JSON.stringify(createObject(4000000, 20, 20))); hannesw@1557: JSON.parse(JSON.stringify(createObject(8000000, 20, 20))); hannesw@1557: JSON.parse(JSON.stringify(createObject(16000000, 20, 20)));