nashorn/test/script/basic/JDK-8134609.js
author hannesw
Fri, 03 Feb 2017 13:28:00 +0100
changeset 43555 1bb10bccf057
parent 32695 9b708b92c695
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:
32695
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
     1
/*
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
     4
 * 
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
     8
 * 
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    13
 * accompanied this code).
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    14
 * 
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    18
 * 
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    21
 * questions.
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    22
 */
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    23
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    24
/**
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    25
 * JDK-8134609: Allow constructors with same prototoype map to share the allocator map
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    26
 *
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    27
 * @test
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    28
 * @run
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    29
 * @fork
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    30
 * @option -Dnashorn.debug
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    31
 */
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    32
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    33
function createProto(members) {
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    34
    function P() {
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    35
        for (var id in members) {
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    36
            if (members.hasOwnProperty(id)) {
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    37
                this[id] = members[id];
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    38
            }
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    39
        }
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    40
        return this;
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    41
    }
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    42
    return new P();
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    43
}
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    44
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    45
function createSubclass(prototype, members) {
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    46
    function C() {
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    47
        for (var id in members) {
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    48
            if (members.hasOwnProperty(id)) {
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    49
                this[id] = members[id];
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    50
            }
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    51
        }
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    52
        return this;
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    53
    }
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    54
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    55
    C.prototype = prototype;
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    56
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    57
    return new C();
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    58
}
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    59
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    60
function assertP1(object, value) {
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    61
    Assert.assertTrue(object.p1 === value);
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    62
}
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    63
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    64
// First prototype will have non-shared proto-map. Second and third will be shared.
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    65
var proto0 = createProto({p1: 0, p2: 1});
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    66
var proto1 = createProto({p1: 1, p2: 2});
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    67
var proto2 = createProto({p1: 2, p2: 3});
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    68
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    69
Assert.assertTrue(Debug.map(proto1) === Debug.map(proto2));
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    70
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    71
assertP1(proto1, 1);
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    72
assertP1(proto2, 2);
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    73
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    74
// First instantiation will have a non-shared prototype map, from the second one
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    75
// maps will be shared until a different proto map comes along.
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    76
var child0 = createSubclass(proto1, {c1: 1, c2: 2});
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    77
var child1 = createSubclass(proto2, {c1: 2, c2: 3});
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    78
var child2 = createSubclass(proto1, {c1: 3, c2: 4});
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    79
var child3 = createSubclass(proto2, {c1: 1, c2: 2});
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    80
var child4 = createSubclass(proto0, {c1: 3, c2: 2});
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    81
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    82
Assert.assertTrue(Debug.map(child1) === Debug.map(child2));
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    83
Assert.assertTrue(Debug.map(child1) === Debug.map(child3));
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    84
Assert.assertTrue(Debug.map(child3) !== Debug.map(child4));
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    85
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    86
assertP1(child1, 2);
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    87
assertP1(child2, 1);
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    88
assertP1(child3, 2);
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    89
assertP1(child4, 0);
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    90
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    91
Assert.assertTrue(delete proto2.p1);
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    92
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    93
assertP1(child3, undefined);
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    94
assertP1(child2, 1);
9b708b92c695 8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff changeset
    95
Assert.assertTrue(Debug.map(child1) !== Debug.map(child3));