Path: blob/aarch64-shenandoah-jdk8u272-b10/nashorn/test/script/nosecurity/JDK-8044851.js
32281 views
/*1* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* JDK-8044851: nashorn properties leak memory25*26* @test27* @run28* @option -Dnashorn.debug=true29* @fork30*/3132function printProperty(value, property) {33print(value, property.getKey(), property.isSpill() ? "spill" : "field", property.getSlot());34}3536var obj = {}, i, name;3738for (i = 0; i < 8; ++i) {39name = 'property' + i;40obj[name] = 'a' + i;41printProperty(obj[name], Debug.map(obj).findProperty(name));42}43print();4445for (i = 0; i < 8; ++i) {46name = 'property' + i;47delete obj[name];48}4950for (i = 0; i < 8; ++i) {51name = 'property' + i;52obj[name] = 'b' + i;53printProperty(obj[name], Debug.map(obj).findProperty(name));54}55print();5657for (i = 0; i < 8; ++i) {58name = 'property' + i;59Object.defineProperty(obj, name, {get: function() {return i;}, set: function(v) {}, configurable: true});60printProperty(obj[name], Debug.map(obj).findProperty(name));61}62print();6364for (i = 0; i < 8; ++i) {65name = 'property' + i;66delete obj[name];67}6869for (i = 0; i < 8; ++i) {70name = 'property' + i;71obj[name] = 'c' + i;72printProperty(obj[name], Debug.map(obj).findProperty(name));73}74print();7576for (i = 7; i > -1; --i) {77name = 'property' + i;78delete obj[name];79}8081for (i = 0; i < 8; ++i) {82name = 'property' + i;83obj[name] = 'd' + i;84printProperty(obj[name], Debug.map(obj).findProperty(name));85}86print();8788for (i = 0; i < 8; ++i) {89name = 'property' + i;90Object.defineProperty(obj, name, {get: function() {return i;}, set: function(v) {}});91printProperty(obj[name], Debug.map(obj).findProperty(name));92}939495