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