author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 50695 | 36ca515343e0 |
permissions | -rw-r--r-- |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
1 |
/* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
4 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
10 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
15 |
* accompanied this code). |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
16 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
20 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
23 |
* questions. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
24 |
*/ |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
25 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
26 |
/* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
27 |
* This file is available under and governed by the GNU General Public |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
28 |
* License version 2 only, as published by the Free Software Foundation. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
29 |
* However, the following notice accompanied the original version of this |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
30 |
* file, and Oracle licenses the original version of this file under the BSD |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
31 |
* license: |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
32 |
*/ |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
33 |
/* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
34 |
Copyright 2009-2013 Attila Szegedi |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
35 |
|
50695 | 36 |
Redistribution and use in source and binary forms, with or without |
37 |
modification, are permitted provided that the following conditions are |
|
38 |
met: |
|
39 |
* Redistributions of source code must retain the above copyright |
|
40 |
notice, this list of conditions and the following disclaimer. |
|
41 |
* Redistributions in binary form must reproduce the above copyright |
|
42 |
notice, this list of conditions and the following disclaimer in the |
|
43 |
documentation and/or other materials provided with the distribution. |
|
44 |
* Neither the name of the copyright holder nor the names of |
|
45 |
contributors may be used to endorse or promote products derived from |
|
46 |
this software without specific prior written permission. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
47 |
|
50695 | 48 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
49 |
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
|
50 |
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
|
51 |
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER |
|
52 |
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
53 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
54 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
|
55 |
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
56 |
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
57 |
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
58 |
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
59 |
*/ |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
60 |
|
34447
ec4c069f9436
8141338: Move jdk.internal.dynalink package to jdk.dynalink
attila
parents:
33337
diff
changeset
|
61 |
package jdk.dynalink.linker; |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
62 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
63 |
import java.lang.invoke.MethodHandle; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
64 |
import java.lang.invoke.MethodHandles; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
65 |
import java.lang.invoke.MethodType; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
66 |
import java.lang.invoke.SwitchPoint; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
67 |
import java.util.List; |
28785
a503c972d4bd
8072595: nashorn should not use obj.getClass() for null checks
sundar
parents:
25865
diff
changeset
|
68 |
import java.util.Objects; |
33335
a46c85103868
8139756: Eliminate GuardedTypeConversion, DynamicLinker.getCurrentLinkRequest and its associated permission
attila
parents:
33333
diff
changeset
|
69 |
import java.util.function.Supplier; |
34447
ec4c069f9436
8141338: Move jdk.internal.dynalink package to jdk.dynalink
attila
parents:
33337
diff
changeset
|
70 |
import jdk.dynalink.CallSiteDescriptor; |
ec4c069f9436
8141338: Move jdk.internal.dynalink package to jdk.dynalink
attila
parents:
33337
diff
changeset
|
71 |
import jdk.dynalink.linker.support.Guards; |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
72 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
73 |
/** |
33333 | 74 |
* Represents a conditionally valid method handle. Usually produced as a return |
75 |
* value of |
|
76 |
* {@link GuardingDynamicLinker#getGuardedInvocation(LinkRequest, LinkerServices)} |
|
33335
a46c85103868
8139756: Eliminate GuardedTypeConversion, DynamicLinker.getCurrentLinkRequest and its associated permission
attila
parents:
33333
diff
changeset
|
77 |
* and |
a46c85103868
8139756: Eliminate GuardedTypeConversion, DynamicLinker.getCurrentLinkRequest and its associated permission
attila
parents:
33333
diff
changeset
|
78 |
* {@link GuardingTypeConverterFactory#convertToType(Class, Class, Supplier)}. |
a46c85103868
8139756: Eliminate GuardedTypeConversion, DynamicLinker.getCurrentLinkRequest and its associated permission
attila
parents:
33333
diff
changeset
|
79 |
* It is an immutable tuple of an invocation method handle, a guard method |
a46c85103868
8139756: Eliminate GuardedTypeConversion, DynamicLinker.getCurrentLinkRequest and its associated permission
attila
parents:
33333
diff
changeset
|
80 |
* handle that defines the applicability of the invocation handle, zero or more |
a46c85103868
8139756: Eliminate GuardedTypeConversion, DynamicLinker.getCurrentLinkRequest and its associated permission
attila
parents:
33333
diff
changeset
|
81 |
* switch points that can be used for external invalidation of the invocation |
a46c85103868
8139756: Eliminate GuardedTypeConversion, DynamicLinker.getCurrentLinkRequest and its associated permission
attila
parents:
33333
diff
changeset
|
82 |
* handle, and an exception type that if thrown during an invocation of the |
a46c85103868
8139756: Eliminate GuardedTypeConversion, DynamicLinker.getCurrentLinkRequest and its associated permission
attila
parents:
33333
diff
changeset
|
83 |
* method handle also invalidates it. The invocation handle is suitable for |
a46c85103868
8139756: Eliminate GuardedTypeConversion, DynamicLinker.getCurrentLinkRequest and its associated permission
attila
parents:
33333
diff
changeset
|
84 |
* invocation if the guard handle returns true for its arguments, and as long |
a46c85103868
8139756: Eliminate GuardedTypeConversion, DynamicLinker.getCurrentLinkRequest and its associated permission
attila
parents:
33333
diff
changeset
|
85 |
* as any of the switch points are not invalidated, and as long as it does not |
a46c85103868
8139756: Eliminate GuardedTypeConversion, DynamicLinker.getCurrentLinkRequest and its associated permission
attila
parents:
33333
diff
changeset
|
86 |
* throw an exception of the designated type. The guard, the switch points, and |
a46c85103868
8139756: Eliminate GuardedTypeConversion, DynamicLinker.getCurrentLinkRequest and its associated permission
attila
parents:
33333
diff
changeset
|
87 |
* the exception type are all optional (a guarded invocation having none of them |
a46c85103868
8139756: Eliminate GuardedTypeConversion, DynamicLinker.getCurrentLinkRequest and its associated permission
attila
parents:
33333
diff
changeset
|
88 |
* is unconditionally valid). |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
89 |
*/ |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
90 |
public class GuardedInvocation { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
91 |
private final MethodHandle invocation; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
92 |
private final MethodHandle guard; |
24719 | 93 |
private final Class<? extends Throwable> exception; |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
94 |
private final SwitchPoint[] switchPoints; |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
95 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
96 |
/** |
33333 | 97 |
* Creates a new unconditional guarded invocation. It is unconditional as it |
98 |
* has no invalidations. |
|
24719 | 99 |
* |
33333 | 100 |
* @param invocation the method handle representing the invocation. Must not |
101 |
* be null. |
|
24719 | 102 |
* @throws NullPointerException if invocation is null. |
103 |
*/ |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
104 |
public GuardedInvocation(final MethodHandle invocation) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
105 |
this(invocation, null, (SwitchPoint)null, null); |
24719 | 106 |
} |
107 |
||
108 |
/** |
|
33333 | 109 |
* Creates a new guarded invocation, with a guard method handle. |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
110 |
* |
33333 | 111 |
* @param invocation the method handle representing the invocation. Must not |
112 |
* be null. |
|
113 |
* @param guard the method handle representing the guard. Must have be |
|
114 |
* compatible with the {@code invocation} handle as per |
|
115 |
* {@link MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle)}. |
|
116 |
* For some useful guards, check out the {@link Guards} class. It can be |
|
117 |
* null to represent an unconditional invocation. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
118 |
* @throws NullPointerException if invocation is null. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
119 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
120 |
public GuardedInvocation(final MethodHandle invocation, final MethodHandle guard) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
121 |
this(invocation, guard, (SwitchPoint)null, null); |
24719 | 122 |
} |
123 |
||
124 |
/** |
|
33333 | 125 |
* Creates a new guarded invocation that can be invalidated by a switch |
126 |
* point. |
|
24719 | 127 |
* |
33333 | 128 |
* @param invocation the method handle representing the invocation. Must |
129 |
* not be null. |
|
130 |
* @param switchPoint the optional switch point that can be used to |
|
131 |
* invalidate this linkage. It can be null. If it is null, this represents |
|
132 |
* an unconditional invocation. |
|
24719 | 133 |
* @throws NullPointerException if invocation is null. |
134 |
*/ |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
135 |
public GuardedInvocation(final MethodHandle invocation, final SwitchPoint switchPoint) { |
24719 | 136 |
this(invocation, null, switchPoint, null); |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
137 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
138 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
139 |
/** |
33333 | 140 |
* Creates a new guarded invocation, with both a guard method handle and a |
141 |
* switch point that can be used to invalidate it. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
142 |
* |
33333 | 143 |
* @param invocation the method handle representing the invocation. Must |
144 |
* not be null. |
|
145 |
* @param guard the method handle representing the guard. Must have be |
|
146 |
* compatible with the {@code invocation} handle as per |
|
147 |
* {@link MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle)}. |
|
148 |
* For some useful guards, check out the {@link Guards} class. It can be |
|
149 |
* null. If both it and the switch point are null, this represents an |
|
150 |
* unconditional invocation. |
|
151 |
* @param switchPoint the optional switch point that can be used to |
|
152 |
* invalidate this linkage. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
153 |
* @throws NullPointerException if invocation is null. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
154 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
155 |
public GuardedInvocation(final MethodHandle invocation, final MethodHandle guard, final SwitchPoint switchPoint) { |
24719 | 156 |
this(invocation, guard, switchPoint, null); |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
157 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
158 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
159 |
/** |
33333 | 160 |
* Creates a new guarded invocation, with a guard method handle, a |
161 |
* switch point that can be used to invalidate it, and an exception that if |
|
162 |
* thrown when invoked also invalidates it. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
163 |
* |
33333 | 164 |
* @param invocation the method handle representing the invocation. Must not |
165 |
* be null. |
|
166 |
* @param guard the method handle representing the guard. Must have be |
|
167 |
* compatible with the {@code invocation} handle as per |
|
168 |
* {@link MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle)}. |
|
169 |
* For some useful guards, check out the {@link Guards} class. It can be |
|
170 |
* null. If it and the switch point and the exception are all null, this |
|
171 |
* represents an unconditional invocation. |
|
172 |
* @param switchPoint the optional switch point that can be used to |
|
173 |
* invalidate this linkage. |
|
174 |
* @param exception the optional exception type that is when thrown by the |
|
175 |
* invocation also invalidates it. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
176 |
* @throws NullPointerException if invocation is null. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
177 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
178 |
public GuardedInvocation(final MethodHandle invocation, final MethodHandle guard, final SwitchPoint switchPoint, final Class<? extends Throwable> exception) { |
28785
a503c972d4bd
8072595: nashorn should not use obj.getClass() for null checks
sundar
parents:
25865
diff
changeset
|
179 |
this.invocation = Objects.requireNonNull(invocation); |
24719 | 180 |
this.guard = guard; |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
181 |
this.switchPoints = switchPoint == null ? null : new SwitchPoint[] { switchPoint }; |
34977
7c1f2143d0f6
8147070: Dynalink GuardedInvocation must check the Class object passed
sundar
parents:
34447
diff
changeset
|
182 |
if (exception != null && !Throwable.class.isAssignableFrom(exception)) { |
7c1f2143d0f6
8147070: Dynalink GuardedInvocation must check the Class object passed
sundar
parents:
34447
diff
changeset
|
183 |
throw new IllegalArgumentException(exception.getName() + " is not assignable from Throwable"); |
7c1f2143d0f6
8147070: Dynalink GuardedInvocation must check the Class object passed
sundar
parents:
34447
diff
changeset
|
184 |
} |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
185 |
this.exception = exception; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
186 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
187 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
188 |
/** |
33333 | 189 |
* Creates a new guarded invocation, with a guard method handle, any number |
190 |
* of switch points that can be used to invalidate it, and an exception that |
|
191 |
* if thrown when invoked also invalidates it. |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
192 |
* |
33333 | 193 |
* @param invocation the method handle representing the invocation. Must not |
194 |
* be null. |
|
195 |
* @param guard the method handle representing the guard. Must have be |
|
196 |
* compatible with the {@code invocation} handle as per |
|
197 |
* {@link MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle)}. |
|
198 |
* For some useful guards, check out the {@link Guards} class. It can be |
|
199 |
* null. If it and the exception are both null, and no switch points were |
|
200 |
* specified, this represents an unconditional invocation. |
|
201 |
* @param switchPoints optional switch points that can be used to |
|
202 |
* invalidate this linkage. |
|
203 |
* @param exception the optional exception type that is when thrown by the |
|
204 |
* invocation also invalidates it. |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
205 |
* @throws NullPointerException if invocation is null. |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
206 |
*/ |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
207 |
public GuardedInvocation(final MethodHandle invocation, final MethodHandle guard, final SwitchPoint[] switchPoints, final Class<? extends Throwable> exception) { |
28785
a503c972d4bd
8072595: nashorn should not use obj.getClass() for null checks
sundar
parents:
25865
diff
changeset
|
208 |
this.invocation = Objects.requireNonNull(invocation); |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
209 |
this.guard = guard; |
25824
ea1f7997ebb2
8051839: GuardedInvocation needs to clone an argument
attila
parents:
24778
diff
changeset
|
210 |
this.switchPoints = switchPoints == null ? null : switchPoints.clone(); |
34977
7c1f2143d0f6
8147070: Dynalink GuardedInvocation must check the Class object passed
sundar
parents:
34447
diff
changeset
|
211 |
if (exception != null && !Throwable.class.isAssignableFrom(exception)) { |
7c1f2143d0f6
8147070: Dynalink GuardedInvocation must check the Class object passed
sundar
parents:
34447
diff
changeset
|
212 |
throw new IllegalArgumentException(exception.getName() + " is not assignable from Throwable"); |
7c1f2143d0f6
8147070: Dynalink GuardedInvocation must check the Class object passed
sundar
parents:
34447
diff
changeset
|
213 |
} |
24719 | 214 |
this.exception = exception; |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
215 |
} |
24719 | 216 |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
217 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
218 |
* Returns the invocation method handle. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
219 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
220 |
* @return the invocation method handle. It will never be null. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
221 |
*/ |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
222 |
public MethodHandle getInvocation() { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
223 |
return invocation; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
224 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
225 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
226 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
227 |
* Returns the guard method handle. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
228 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
229 |
* @return the guard method handle. Can be null. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
230 |
*/ |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
231 |
public MethodHandle getGuard() { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
232 |
return guard; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
233 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
234 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
235 |
/** |
33333 | 236 |
* Returns the switch points that can be used to invalidate the linkage of |
237 |
* this invocation handle. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
238 |
* |
33333 | 239 |
* @return the switch points that can be used to invalidate the linkage of |
240 |
* this invocation handle. Can be null. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
241 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
242 |
public SwitchPoint[] getSwitchPoints() { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
243 |
return switchPoints == null ? null : switchPoints.clone(); |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
244 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
245 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
246 |
/** |
33333 | 247 |
* Returns the exception type that if thrown by the invocation should |
248 |
* invalidate the linkage of this guarded invocation. |
|
24719 | 249 |
* |
33333 | 250 |
* @return the exception type that if thrown should be used to invalidate |
251 |
* the linkage. Can be null. |
|
24719 | 252 |
*/ |
253 |
public Class<? extends Throwable> getException() { |
|
254 |
return exception; |
|
255 |
} |
|
256 |
||
257 |
/** |
|
33333 | 258 |
* Returns true if and only if this guarded invocation has at least one |
259 |
* invalidated switch point. |
|
260 |
* @return true if and only if this guarded invocation has at least one |
|
261 |
* invalidated switch point. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
262 |
*/ |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
263 |
public boolean hasBeenInvalidated() { |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
264 |
if (switchPoints == null) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
265 |
return false; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
266 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
267 |
for (final SwitchPoint sp : switchPoints) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
268 |
if (sp.hasBeenInvalidated()) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
269 |
return true; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
270 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
271 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
272 |
return false; |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
273 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
274 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
275 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
276 |
* Creates a new guarded invocation with different methods, preserving the switch point. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
277 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
278 |
* @param newInvocation the new invocation |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
279 |
* @param newGuard the new guard |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
280 |
* @return a new guarded invocation with the replaced methods and the same switch point as this invocation. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
281 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
282 |
public GuardedInvocation replaceMethods(final MethodHandle newInvocation, final MethodHandle newGuard) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
283 |
return new GuardedInvocation(newInvocation, newGuard, switchPoints, exception); |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
284 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
285 |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
286 |
/** |
33333 | 287 |
* Create a new guarded invocation with an added switch point. |
288 |
* @param newSwitchPoint new switch point. Can be null in which case this |
|
289 |
* method return the current guarded invocation with no changes. |
|
290 |
* @return a guarded invocation with the added switch point. |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
291 |
*/ |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
292 |
public GuardedInvocation addSwitchPoint(final SwitchPoint newSwitchPoint) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
293 |
if (newSwitchPoint == null) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
294 |
return this; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
295 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
296 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
297 |
final SwitchPoint[] newSwitchPoints; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
298 |
if (switchPoints != null) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
299 |
newSwitchPoints = new SwitchPoint[switchPoints.length + 1]; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
300 |
System.arraycopy(switchPoints, 0, newSwitchPoints, 0, switchPoints.length); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
301 |
newSwitchPoints[switchPoints.length] = newSwitchPoint; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
302 |
} else { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
303 |
newSwitchPoints = new SwitchPoint[] { newSwitchPoint }; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
304 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
305 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
306 |
return new GuardedInvocation(invocation, guard, newSwitchPoints, exception); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
307 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
308 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
309 |
private GuardedInvocation replaceMethodsOrThis(final MethodHandle newInvocation, final MethodHandle newGuard) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
310 |
if (newInvocation == invocation && newGuard == guard) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
311 |
return this; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
312 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
313 |
return replaceMethods(newInvocation, newGuard); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
314 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
315 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
316 |
/** |
33333 | 317 |
* Changes the type of the invocation, as if |
318 |
* {@link MethodHandle#asType(MethodType)} was applied to its invocation |
|
319 |
* and its guard, if it has one (with return type changed to boolean, and |
|
320 |
* parameter count potentially truncated for the guard). If the invocation |
|
321 |
* already is of the required type, returns this object. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
322 |
* @param newType the new type of the invocation. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
323 |
* @return a guarded invocation with the new type applied to it. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
324 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
325 |
public GuardedInvocation asType(final MethodType newType) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
326 |
return replaceMethodsOrThis(invocation.asType(newType), guard == null ? null : Guards.asType(guard, newType)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
327 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
328 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
329 |
/** |
33333 | 330 |
* Changes the type of the invocation, as if |
331 |
* {@link LinkerServices#asType(MethodHandle, MethodType)} was applied to |
|
332 |
* its invocation and its guard, if it has one (with return type changed to |
|
333 |
* boolean, and parameter count potentially truncated for the guard). If the |
|
334 |
* invocation already is of the required type, returns this object. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
335 |
* @param linkerServices the linker services to use for the conversion |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
336 |
* @param newType the new type of the invocation. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
337 |
* @return a guarded invocation with the new type applied to it. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
338 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
339 |
public GuardedInvocation asType(final LinkerServices linkerServices, final MethodType newType) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
340 |
return replaceMethodsOrThis(linkerServices.asType(invocation, newType), guard == null ? null : |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
341 |
Guards.asType(linkerServices, guard, newType)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
342 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
343 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
344 |
/** |
33333 | 345 |
* Changes the type of the invocation, as if |
346 |
* {@link LinkerServices#asTypeLosslessReturn(MethodHandle, MethodType)} was |
|
347 |
* applied to its invocation and |
|
348 |
* {@link LinkerServices#asType(MethodHandle, MethodType)} applied to its |
|
349 |
* guard, if it has one (with return type changed to boolean, and parameter |
|
350 |
* count potentially truncated for the guard). If the invocation doesn't |
|
351 |
* change its type, returns this object. |
|
24719 | 352 |
* @param linkerServices the linker services to use for the conversion |
353 |
* @param newType the new type of the invocation. |
|
354 |
* @return a guarded invocation with the new type applied to it. |
|
355 |
*/ |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
356 |
public GuardedInvocation asTypeSafeReturn(final LinkerServices linkerServices, final MethodType newType) { |
24719 | 357 |
return replaceMethodsOrThis(linkerServices.asTypeLosslessReturn(invocation, newType), guard == null ? null : |
358 |
Guards.asType(linkerServices, guard, newType)); |
|
359 |
} |
|
360 |
||
361 |
/** |
|
33333 | 362 |
* Changes the type of the invocation, as if |
363 |
* {@link MethodHandle#asType(MethodType)} was applied to its invocation |
|
364 |
* and its guard, if it has one (with return type changed to boolean for |
|
365 |
* guard). If the invocation already is of the required type, returns this |
|
366 |
* object. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
367 |
* @param desc a call descriptor whose method type is adapted. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
368 |
* @return a guarded invocation with the new type applied to it. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
369 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
370 |
public GuardedInvocation asType(final CallSiteDescriptor desc) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
371 |
return asType(desc.getMethodType()); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
372 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
373 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
374 |
/** |
43349 | 375 |
* Applies argument filters to both the invocation and the guard |
376 |
* (if it exists and has at least {@code pos + 1} parameters) with |
|
377 |
* {@link MethodHandles#filterArguments(MethodHandle, int, MethodHandle...)}. |
|
32534
b3ec7f3b3c2a
8136349: Typos patch for nashorn sources submitted on Sep 10, 2015
sundar
parents:
28785
diff
changeset
|
378 |
* @param pos the position of the first argument being filtered |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
379 |
* @param filters the argument filters |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
380 |
* @return a filtered invocation |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
381 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
382 |
public GuardedInvocation filterArguments(final int pos, final MethodHandle... filters) { |
43349 | 383 |
return replaceMethods(MethodHandles.filterArguments(invocation, pos, filters), |
384 |
guard == null || pos >= guard.type().parameterCount() ? |
|
385 |
guard : MethodHandles.filterArguments(guard, pos, filters)); |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
386 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
387 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
388 |
/** |
33333 | 389 |
* Makes an invocation that drops arguments in both the invocation and the |
43349 | 390 |
* guard (if it exists and has at least {@code pos} parameters) with |
391 |
* {@link MethodHandles#dropArguments(MethodHandle, int, List)}. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
392 |
* @param pos the position of the first argument being dropped |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
393 |
* @param valueTypes the types of the values being dropped |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
394 |
* @return an invocation that drops arguments |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
395 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
396 |
public GuardedInvocation dropArguments(final int pos, final List<Class<?>> valueTypes) { |
43349 | 397 |
return replaceMethods(MethodHandles.dropArguments(invocation, pos, valueTypes), |
398 |
guard == null || pos > guard.type().parameterCount() ? |
|
399 |
guard : MethodHandles.dropArguments(guard, pos, valueTypes)); |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
400 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
401 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
402 |
/** |
33333 | 403 |
* Makes an invocation that drops arguments in both the invocation and the |
43349 | 404 |
* guard (if it exists and has at least {@code pos} parameters) with |
405 |
* {@link MethodHandles#dropArguments(MethodHandle, int, Class...)}. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
406 |
* @param pos the position of the first argument being dropped |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
407 |
* @param valueTypes the types of the values being dropped |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
408 |
* @return an invocation that drops arguments |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
409 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
410 |
public GuardedInvocation dropArguments(final int pos, final Class<?>... valueTypes) { |
43349 | 411 |
return replaceMethods(MethodHandles.dropArguments(invocation, pos, valueTypes), |
412 |
guard == null || pos > guard.type().parameterCount() ? |
|
413 |
guard : MethodHandles.dropArguments(guard, pos, valueTypes)); |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
414 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
415 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
416 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
417 |
/** |
33333 | 418 |
* Composes the invocation, guard, switch points, and the exception into a |
419 |
* composite method handle that knows how to fall back when the guard fails |
|
420 |
* or the invocation is invalidated. |
|
421 |
* @param fallback the fallback method handle for when a switch point is |
|
422 |
* invalidated, a guard returns false, or invalidating exception is thrown. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
423 |
* @return a composite method handle. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
424 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
425 |
public MethodHandle compose(final MethodHandle fallback) { |
24720 | 426 |
return compose(fallback, fallback, fallback); |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
427 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
428 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
429 |
/** |
33333 | 430 |
* Composes the invocation, guard, switch points, and the exception into a |
431 |
* composite method handle that knows how to fall back when the guard fails |
|
432 |
* or the invocation is invalidated. |
|
433 |
* @param switchpointFallback the fallback method handle in case a switch |
|
434 |
* point is invalidated. |
|
435 |
* @param guardFallback the fallback method handle in case guard returns |
|
436 |
* false. |
|
437 |
* @param catchFallback the fallback method in case the exception handler |
|
438 |
* triggers. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
439 |
* @return a composite method handle. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
440 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
441 |
public MethodHandle compose(final MethodHandle guardFallback, final MethodHandle switchpointFallback, final MethodHandle catchFallback) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
442 |
final MethodHandle guarded = |
24720 | 443 |
guard == null ? |
444 |
invocation : |
|
445 |
MethodHandles.guardWithTest( |
|
446 |
guard, |
|
447 |
invocation, |
|
448 |
guardFallback); |
|
449 |
||
450 |
final MethodHandle catchGuarded = |
|
451 |
exception == null ? |
|
452 |
guarded : |
|
33333 | 453 |
MethodHandles.catchException( |
24720 | 454 |
guarded, |
455 |
exception, |
|
456 |
MethodHandles.dropArguments( |
|
457 |
catchFallback, |
|
458 |
0, |
|
459 |
exception)); |
|
460 |
||
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
461 |
if (switchPoints == null) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
462 |
return catchGuarded; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
463 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
464 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
465 |
MethodHandle spGuarded = catchGuarded; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
466 |
for (final SwitchPoint sp : switchPoints) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
467 |
spGuarded = sp.guardWithTest(spGuarded, switchpointFallback); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
468 |
} |
24720 | 469 |
|
470 |
return spGuarded; |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
471 |
} |
16245
6a1c6c8bc113
8008371: Fix Dynalink compiler warnings and whitespace
attila
parents:
16234
diff
changeset
|
472 |
} |