nashorn/test/script/basic/JDK-8026367.js
author hannesw
Fri, 03 Feb 2017 13:28:00 +0100
changeset 43555 1bb10bccf057
parent 36141 696d662bcdb7
permissions -rw-r--r--
8173888: Test for JDK-8169481 causes stack overflows in parser tests Reviewed-by: jlaskey, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20946
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
     1
/*
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 20946
diff changeset
     4
 *
20946
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 20946
diff changeset
     8
 *
20946
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    13
 * accompanied this code).
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 20946
diff changeset
    14
 *
20946
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 20946
diff changeset
    18
 *
20946
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    21
 * questions.
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    22
 */
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    23
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    24
/**
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    25
 * JDK-8026367: Add a sync keyword to mozilla_compat
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    26
 *
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    27
 * @test
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    28
 * @run
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    29
 */
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    30
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    31
if (typeof sync === "undefined") {
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    32
    load("nashorn:mozilla_compat.js");
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    33
}
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    34
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    35
var obj = {
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    36
    count: 0,
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    37
    // Sync called with one argument will synchronize on this-object of invocation
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    38
    inc: sync(function(d) {
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    39
        this.count += d;
36141
696d662bcdb7 8148379: jdk.nashorn.api.scripting spec. adjustments, clarifications
sundar
parents: 24778
diff changeset
    40
        Assert.assertTrue(java.lang.Thread.holdsLock(this));
20946
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    41
    }),
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    42
    // Pass explicit object to synchronize on as second argument
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    43
    dec: sync(function(d) {
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    44
        this.count -= d;
36141
696d662bcdb7 8148379: jdk.nashorn.api.scripting spec. adjustments, clarifications
sundar
parents: 24778
diff changeset
    45
        Assert.assertTrue(java.lang.Thread.holdsLock(obj));
20946
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    46
    }, obj)
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    47
};
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    48
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    49
var t1 = new java.lang.Thread(function() {
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    50
    for (var i = 0; i < 100000; i++) obj.inc(1);
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    51
});
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    52
var t2 = new java.lang.Thread(function() {
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    53
    for (var i = 0; i < 100000; i++) obj.dec(1);
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    54
});
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    55
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    56
t1.start();
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    57
t2.start();
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    58
t1.join();
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    59
t2.join();
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    60
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    61
if (obj.count !== 0) {
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    62
    throw new Error("Expected count == 0, got " + obj.count);
bd3d6e87ec6b 8026367: Add a sync keyword to mozilla_compat
hannesw
parents:
diff changeset
    63
}