author | darcy |
Fri, 27 Sep 2019 08:57:25 -0700 | |
changeset 58379 | 8511c662083b |
parent 47713 | 530f16bacbfd |
permissions | -rw-r--r-- |
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
1 |
/* |
58379
8511c662083b
8231557: Suppress warnings on non-serializable instance fields in jdk.scripting.nashorn module
darcy
parents:
47713
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
32695
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. Oracle designates this |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
10 |
* |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
11 |
* 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
|
12 |
* 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
|
13 |
* 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
|
14 |
* 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
|
15 |
* accompanied this code). |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
16 |
* |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
17 |
* 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
|
18 |
* 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
|
19 |
* 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
|
20 |
* |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
21 |
* 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
|
22 |
* 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
|
23 |
* questions. |
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 |
|
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
26 |
package jdk.nashorn.internal.runtime; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
27 |
|
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
28 |
import java.lang.invoke.SwitchPoint; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
29 |
|
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
30 |
/** |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
31 |
* This class represents a property map that can be shared among multiple prototype objects, allowing all inheriting |
40824
c24d212a8733
8077149: __noSuchProperty__ and __noSuchMethod__ invocations are not properly guarded
hannesw
parents:
32695
diff
changeset
|
32 |
* top-level objects to also share one property map. This class is only used for prototype objects, the |
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
33 |
* top-level objects use ordinary {@link PropertyMap}s with the {@link PropertyMap#sharedProtoMap} field |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
34 |
* set to the expected shared prototype map. |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
35 |
* |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
36 |
* <p>When an instance of this class is evolved because a property is added, removed, or modified in an object |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
37 |
* using it, the {@link #invalidateSwitchPoint()} method is invoked to signal to all callsites and inheriting |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
38 |
* objects that the assumption of a single shared prototype map is no longer valid. The property map resulting |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
39 |
* from the modification will no longer be an instance of this class.</p> |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
40 |
*/ |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
41 |
public final class SharedPropertyMap extends PropertyMap { |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
42 |
|
58379
8511c662083b
8231557: Suppress warnings on non-serializable instance fields in jdk.scripting.nashorn module
darcy
parents:
47713
diff
changeset
|
43 |
@SuppressWarnings("serial") // Not statically typed as Serializable |
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
44 |
private SwitchPoint switchPoint; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
45 |
|
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
46 |
private static final long serialVersionUID = 2166297719721778876L; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
47 |
|
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
48 |
/** |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
49 |
* Create a new shared property map from the given {@code map}. |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
50 |
* @param map property map to copy |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
51 |
*/ |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
52 |
SharedPropertyMap(final PropertyMap map) { |
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
53 |
super(map); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
54 |
this.switchPoint = new SwitchPoint(); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
55 |
} |
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 |
@Override |
47713
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
58 |
public void propertyChanged(final Property property) { |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
59 |
invalidateSwitchPoint(); |
530f16bacbfd
8190427: Test for JDK-8165198 fails intermittently because of GC
hannesw
parents:
47216
diff
changeset
|
60 |
super.propertyChanged(property); |
32695
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
61 |
} |
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 |
@Override |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
64 |
synchronized boolean isValidSharedProtoMap() { |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
65 |
return switchPoint != null; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
66 |
} |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
67 |
|
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
68 |
@Override |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
69 |
synchronized SwitchPoint getSharedProtoSwitchPoint() { |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
70 |
return switchPoint; |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
71 |
} |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
72 |
|
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 |
* Invalidate the shared prototype switch point if this is a shared prototype map. |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
75 |
*/ |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
76 |
synchronized void invalidateSwitchPoint() { |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
77 |
if (switchPoint != null) { |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
78 |
assert !switchPoint.hasBeenInvalidated(); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
79 |
SwitchPoint.invalidateAll(new SwitchPoint[]{ switchPoint }); |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
80 |
switchPoint = null; |
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 |
} |
9b708b92c695
8134609: Allow constructors with same prototoype map to share the allocator map
hannesw
parents:
diff
changeset
|
83 |
} |