Mon, 07 Dec 2015 13:15:47 -0800
Merge
sundar@1534 | 1 | /* |
sundar@1534 | 2 | * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
sundar@1534 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
sundar@1534 | 4 | * |
sundar@1534 | 5 | * This code is free software; you can redistribute it and/or modify it |
sundar@1534 | 6 | * under the terms of the GNU General Public License version 2 only, as |
sundar@1534 | 7 | * published by the Free Software Foundation. |
sundar@1534 | 8 | * |
sundar@1534 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
sundar@1534 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
sundar@1534 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
sundar@1534 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
sundar@1534 | 13 | * accompanied this code). |
sundar@1534 | 14 | * |
sundar@1534 | 15 | * You should have received a copy of the GNU General Public License version |
sundar@1534 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
sundar@1534 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
sundar@1534 | 18 | * |
sundar@1534 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
sundar@1534 | 20 | * or visit www.oracle.com if you need additional information or have any |
sundar@1534 | 21 | * questions. |
sundar@1534 | 22 | */ |
sundar@1534 | 23 | |
sundar@1534 | 24 | /** |
sundar@1534 | 25 | * JDK-8136544: Call site switching to megamorphic causes incorrect property read |
sundar@1534 | 26 | * |
sundar@1534 | 27 | * @test |
sundar@1534 | 28 | * @fork |
sundar@1534 | 29 | * @option -Dnashorn.unstable.relink.threshold=8 |
sundar@1534 | 30 | * @run |
sundar@1534 | 31 | */ |
sundar@1534 | 32 | |
sundar@1534 | 33 | var ScriptContext = Java.type("javax.script.ScriptContext"); |
sundar@1534 | 34 | var ScriptEngineManager = Java.type("javax.script.ScriptEngineManager"); |
sundar@1534 | 35 | var m = new ScriptEngineManager(); |
sundar@1534 | 36 | var e = m.getEngineByName("nashorn"); |
sundar@1534 | 37 | |
sundar@1534 | 38 | var scope = e.getBindings(ScriptContext.ENGINE_SCOPE); |
sundar@1534 | 39 | var MYVAR = "myvar"; |
sundar@1534 | 40 | |
sundar@1534 | 41 | function loopupVar() { |
sundar@1534 | 42 | try { |
sundar@1534 | 43 | e.eval(MYVAR); |
sundar@1534 | 44 | return true; |
sundar@1534 | 45 | } catch (e) { |
sundar@1534 | 46 | return false; |
sundar@1534 | 47 | } |
sundar@1534 | 48 | } |
sundar@1534 | 49 | |
sundar@1534 | 50 | // make sure we exercise callsite beyond megamorphic threshold we set |
sundar@1534 | 51 | // in this test via nashorn.unstable.relink.threshold property |
sundar@1534 | 52 | // In each iteration, callsite is exercised twice (two evals) |
sundar@1534 | 53 | // So, LIMIT should be more than 4 to exercise megamorphic callsites. |
sundar@1534 | 54 | |
sundar@1534 | 55 | var LIMIT = 5; // This LIMIT should be more than 4 |
sundar@1534 | 56 | |
sundar@1534 | 57 | for (var i = 0; i < LIMIT; i++) { |
sundar@1534 | 58 | // remove the variable and lookup |
sundar@1534 | 59 | delete scope[MYVAR]; |
sundar@1534 | 60 | Assert.assertFalse(loopupVar(), "Expected true in iteration " + i); |
sundar@1534 | 61 | |
sundar@1534 | 62 | // set that variable and check again |
sundar@1534 | 63 | scope[MYVAR] = "foo"; |
sundar@1534 | 64 | Assert.assertTrue(loopupVar(), "Expected false in iteration " + i); |
sundar@1534 | 65 | } |