author | attila |
Mon, 19 Oct 2015 08:45:29 +0200 | |
changeset 33333 | 0bad500ce4e0 |
parent 33007 | 03119bfefbbf |
child 33335 | a46c85103868 |
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 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
36 |
Licensed under both the Apache License, Version 2.0 (the "Apache License") |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
37 |
and the BSD License (the "BSD License"), with licensee being free to |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
38 |
choose either of the two at their discretion. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
39 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
40 |
You may not use this file except in compliance with either the Apache |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
41 |
License or the BSD License. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
42 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
43 |
If you choose to use this file in compliance with the Apache License, the |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
44 |
following notice applies to you: |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
45 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
46 |
You may obtain a copy of the Apache License at |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
47 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
48 |
http://www.apache.org/licenses/LICENSE-2.0 |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
49 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
50 |
Unless required by applicable law or agreed to in writing, software |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
51 |
distributed under the License is distributed on an "AS IS" BASIS, |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
52 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
53 |
implied. See the License for the specific language governing |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
54 |
permissions and limitations under the License. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
55 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
56 |
If you choose to use this file in compliance with the BSD License, the |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
57 |
following notice applies to you: |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
58 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
59 |
Redistribution and use in source and binary forms, with or without |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
60 |
modification, are permitted provided that the following conditions are |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
61 |
met: |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
62 |
* Redistributions of source code must retain the above copyright |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
63 |
notice, this list of conditions and the following disclaimer. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
64 |
* Redistributions in binary form must reproduce the above copyright |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
65 |
notice, this list of conditions and the following disclaimer in the |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
66 |
documentation and/or other materials provided with the distribution. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
67 |
* Neither the name of the copyright holder nor the names of |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
68 |
contributors may be used to endorse or promote products derived from |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
69 |
this software without specific prior written permission. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
70 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
71 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
72 |
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
73 |
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
74 |
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
75 |
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
76 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
77 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
78 |
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
79 |
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
80 |
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
81 |
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
82 |
*/ |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
83 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
84 |
package jdk.internal.dynalink.linker; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
85 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
86 |
import java.lang.invoke.MethodHandle; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
87 |
import java.lang.invoke.MethodHandles; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
88 |
import java.lang.invoke.MethodType; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
89 |
import java.lang.invoke.SwitchPoint; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
90 |
import java.util.List; |
28785
a503c972d4bd
8072595: nashorn should not use obj.getClass() for null checks
sundar
parents:
25865
diff
changeset
|
91 |
import java.util.Objects; |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
92 |
import jdk.internal.dynalink.CallSiteDescriptor; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
93 |
import jdk.internal.dynalink.support.Guards; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
94 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
95 |
/** |
33333 | 96 |
* Represents a conditionally valid method handle. Usually produced as a return |
97 |
* value of |
|
98 |
* {@link GuardingDynamicLinker#getGuardedInvocation(LinkRequest, LinkerServices)} |
|
99 |
* and {@link GuardingTypeConverterFactory#convertToType(Class, Class)}. It is |
|
100 |
* an immutable tuple of an invocation method handle, a guard method handle that |
|
101 |
* defines the applicability of the invocation handle, zero or more switch |
|
102 |
* points that can be used for external invalidation of the invocation handle, |
|
103 |
* and an exception type that if thrown during an invocation of the method |
|
104 |
* handle also invalidates it. The invocation handle is suitable for invocation |
|
105 |
* if the guard handle returns true for its arguments, and as long as any of the |
|
106 |
* switch points are not invalidated, and as long as it does not throw an |
|
107 |
* exception of the designated type. The guard, the switch point, and the |
|
108 |
* exception type are all optional (a guarded invocation having none of them is |
|
109 |
* unconditionally valid). |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
110 |
*/ |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
111 |
public class GuardedInvocation { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
112 |
private final MethodHandle invocation; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
113 |
private final MethodHandle guard; |
24719 | 114 |
private final Class<? extends Throwable> exception; |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
115 |
private final SwitchPoint[] switchPoints; |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
116 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
117 |
/** |
33333 | 118 |
* Creates a new unconditional guarded invocation. It is unconditional as it |
119 |
* has no invalidations. |
|
24719 | 120 |
* |
33333 | 121 |
* @param invocation the method handle representing the invocation. Must not |
122 |
* be null. |
|
24719 | 123 |
* @throws NullPointerException if invocation is null. |
124 |
*/ |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
125 |
public GuardedInvocation(final MethodHandle invocation) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
126 |
this(invocation, null, (SwitchPoint)null, null); |
24719 | 127 |
} |
128 |
||
129 |
/** |
|
33333 | 130 |
* Creates a new guarded invocation, with a guard method handle. |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
131 |
* |
33333 | 132 |
* @param invocation the method handle representing the invocation. Must not |
133 |
* be null. |
|
134 |
* @param guard the method handle representing the guard. Must have be |
|
135 |
* compatible with the {@code invocation} handle as per |
|
136 |
* {@link MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle)}. |
|
137 |
* For some useful guards, check out the {@link Guards} class. It can be |
|
138 |
* null to represent an unconditional invocation. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
139 |
* @throws NullPointerException if invocation is null. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
140 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
141 |
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
|
142 |
this(invocation, guard, (SwitchPoint)null, null); |
24719 | 143 |
} |
144 |
||
145 |
/** |
|
33333 | 146 |
* Creates a new guarded invocation that can be invalidated by a switch |
147 |
* point. |
|
24719 | 148 |
* |
33333 | 149 |
* @param invocation the method handle representing the invocation. Must |
150 |
* not be null. |
|
151 |
* @param switchPoint the optional switch point that can be used to |
|
152 |
* invalidate this linkage. It can be null. If it is null, this represents |
|
153 |
* an unconditional invocation. |
|
24719 | 154 |
* @throws NullPointerException if invocation is null. |
155 |
*/ |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
156 |
public GuardedInvocation(final MethodHandle invocation, final SwitchPoint switchPoint) { |
24719 | 157 |
this(invocation, null, switchPoint, null); |
16234
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 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
160 |
/** |
33333 | 161 |
* Creates a new guarded invocation, with both a guard method handle and a |
162 |
* switch point that can be used to invalidate 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 |
165 |
* not 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 both it and the switch point are null, this represents an |
|
171 |
* unconditional invocation. |
|
172 |
* @param switchPoint the optional switch point that can be used to |
|
173 |
* invalidate this linkage. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
174 |
* @throws NullPointerException if invocation is null. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
175 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
176 |
public GuardedInvocation(final MethodHandle invocation, final MethodHandle guard, final SwitchPoint switchPoint) { |
24719 | 177 |
this(invocation, guard, switchPoint, null); |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
178 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
179 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
180 |
/** |
33333 | 181 |
* Creates a new guarded invocation, with a guard method handle, a |
182 |
* switch point that can be used to invalidate it, and an exception that if |
|
183 |
* thrown when invoked also invalidates it. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
184 |
* |
33333 | 185 |
* @param invocation the method handle representing the invocation. Must not |
186 |
* be null. |
|
187 |
* @param guard the method handle representing the guard. Must have be |
|
188 |
* compatible with the {@code invocation} handle as per |
|
189 |
* {@link MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle)}. |
|
190 |
* For some useful guards, check out the {@link Guards} class. It can be |
|
191 |
* null. If it and the switch point and the exception are all null, this |
|
192 |
* represents an unconditional invocation. |
|
193 |
* @param switchPoint the optional switch point that can be used to |
|
194 |
* invalidate this linkage. |
|
195 |
* @param exception the optional exception type that is when thrown by the |
|
196 |
* invocation also invalidates it. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
197 |
* @throws NullPointerException if invocation is null. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
198 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
199 |
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
|
200 |
this.invocation = Objects.requireNonNull(invocation); |
24719 | 201 |
this.guard = guard; |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
202 |
this.switchPoints = switchPoint == null ? null : new SwitchPoint[] { switchPoint }; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
203 |
this.exception = exception; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
204 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
205 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
206 |
/** |
33333 | 207 |
* Creates a new guarded invocation, with a guard method handle, any number |
208 |
* of switch points that can be used to invalidate it, and an exception that |
|
209 |
* 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
|
210 |
* |
33333 | 211 |
* @param invocation the method handle representing the invocation. Must not |
212 |
* be null. |
|
213 |
* @param guard the method handle representing the guard. Must have be |
|
214 |
* compatible with the {@code invocation} handle as per |
|
215 |
* {@link MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle)}. |
|
216 |
* For some useful guards, check out the {@link Guards} class. It can be |
|
217 |
* null. If it and the exception are both null, and no switch points were |
|
218 |
* specified, this represents an unconditional invocation. |
|
219 |
* @param switchPoints optional switch points that can be used to |
|
220 |
* invalidate this linkage. |
|
221 |
* @param exception the optional exception type that is when thrown by the |
|
222 |
* invocation also invalidates it. |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
223 |
* @throws NullPointerException if invocation is null. |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
224 |
*/ |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
225 |
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
|
226 |
this.invocation = Objects.requireNonNull(invocation); |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
227 |
this.guard = guard; |
25824
ea1f7997ebb2
8051839: GuardedInvocation needs to clone an argument
attila
parents:
24778
diff
changeset
|
228 |
this.switchPoints = switchPoints == null ? null : switchPoints.clone(); |
24719 | 229 |
this.exception = exception; |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
230 |
} |
24719 | 231 |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
232 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
233 |
* Returns the invocation method handle. |
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 |
* @return the invocation method handle. It will never be null. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
236 |
*/ |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
237 |
public MethodHandle getInvocation() { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
238 |
return invocation; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
239 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
240 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
241 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
242 |
* Returns the guard method handle. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
243 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
244 |
* @return the guard method handle. Can be null. |
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 |
public MethodHandle getGuard() { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
247 |
return guard; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
248 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
249 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
250 |
/** |
33333 | 251 |
* Returns the switch points that can be used to invalidate the linkage of |
252 |
* this invocation handle. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
253 |
* |
33333 | 254 |
* @return the switch points that can be used to invalidate the linkage of |
255 |
* this invocation handle. Can be null. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
256 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
257 |
public SwitchPoint[] getSwitchPoints() { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
258 |
return switchPoints == null ? null : switchPoints.clone(); |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
259 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
260 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
261 |
/** |
33333 | 262 |
* Returns the exception type that if thrown by the invocation should |
263 |
* invalidate the linkage of this guarded invocation. |
|
24719 | 264 |
* |
33333 | 265 |
* @return the exception type that if thrown should be used to invalidate |
266 |
* the linkage. Can be null. |
|
24719 | 267 |
*/ |
268 |
public Class<? extends Throwable> getException() { |
|
269 |
return exception; |
|
270 |
} |
|
271 |
||
272 |
/** |
|
33333 | 273 |
* Returns true if and only if this guarded invocation has at least one |
274 |
* invalidated switch point. |
|
275 |
* @return true if and only if this guarded invocation has at least one |
|
276 |
* invalidated switch point. |
|
16234
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 |
public boolean hasBeenInvalidated() { |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
279 |
if (switchPoints == null) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
280 |
return false; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
281 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
282 |
for (final SwitchPoint sp : switchPoints) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
283 |
if (sp.hasBeenInvalidated()) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
284 |
return true; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
285 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
286 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
287 |
return false; |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
288 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
289 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
290 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
291 |
* 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
|
292 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
293 |
* @param newInvocation the new invocation |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
294 |
* @param newGuard the new guard |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
295 |
* @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
|
296 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
297 |
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
|
298 |
return new GuardedInvocation(newInvocation, newGuard, switchPoints, exception); |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
299 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
300 |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
301 |
/** |
33333 | 302 |
* Create a new guarded invocation with an added switch point. |
303 |
* @param newSwitchPoint new switch point. Can be null in which case this |
|
304 |
* method return the current guarded invocation with no changes. |
|
305 |
* @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
|
306 |
*/ |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
307 |
public GuardedInvocation addSwitchPoint(final SwitchPoint newSwitchPoint) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
308 |
if (newSwitchPoint == null) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
309 |
return this; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
310 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
311 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
312 |
final SwitchPoint[] newSwitchPoints; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
313 |
if (switchPoints != null) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
314 |
newSwitchPoints = new SwitchPoint[switchPoints.length + 1]; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
315 |
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
|
316 |
newSwitchPoints[switchPoints.length] = newSwitchPoint; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
317 |
} else { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
318 |
newSwitchPoints = new SwitchPoint[] { newSwitchPoint }; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
319 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
320 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
321 |
return new GuardedInvocation(invocation, guard, newSwitchPoints, exception); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
322 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
323 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
324 |
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
|
325 |
if (newInvocation == invocation && newGuard == guard) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
326 |
return this; |
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 |
return replaceMethods(newInvocation, newGuard); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
329 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
330 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
331 |
/** |
33333 | 332 |
* Changes the type of the invocation, as if |
333 |
* {@link MethodHandle#asType(MethodType)} was applied to its invocation |
|
334 |
* and its guard, if it has one (with return type changed to boolean, and |
|
335 |
* parameter count potentially truncated for the guard). If the invocation |
|
336 |
* already is of the required type, returns this object. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
337 |
* @param newType the new type of the invocation. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
338 |
* @return a guarded invocation with the new type applied to it. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
339 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
340 |
public GuardedInvocation asType(final MethodType newType) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
341 |
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
|
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#asType(MethodHandle, MethodType)} was applied to |
|
347 |
* its invocation and its guard, if it has one (with return type changed to |
|
348 |
* boolean, and parameter count potentially truncated for the guard). If the |
|
349 |
* invocation already is of the required type, returns this object. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
350 |
* @param linkerServices the linker services to use for the conversion |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
351 |
* @param newType the new type of the invocation. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
352 |
* @return a guarded invocation with the new type applied to it. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
353 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
354 |
public GuardedInvocation asType(final LinkerServices linkerServices, final MethodType newType) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
355 |
return replaceMethodsOrThis(linkerServices.asType(invocation, newType), guard == null ? null : |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
356 |
Guards.asType(linkerServices, guard, newType)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
357 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
358 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
359 |
/** |
33333 | 360 |
* Changes the type of the invocation, as if |
361 |
* {@link LinkerServices#asTypeLosslessReturn(MethodHandle, MethodType)} was |
|
362 |
* applied to its invocation and |
|
363 |
* {@link LinkerServices#asType(MethodHandle, MethodType)} applied to its |
|
364 |
* guard, if it has one (with return type changed to boolean, and parameter |
|
365 |
* count potentially truncated for the guard). If the invocation doesn't |
|
366 |
* change its type, returns this object. |
|
24719 | 367 |
* @param linkerServices the linker services to use for the conversion |
368 |
* @param newType the new type of the invocation. |
|
369 |
* @return a guarded invocation with the new type applied to it. |
|
370 |
*/ |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
371 |
public GuardedInvocation asTypeSafeReturn(final LinkerServices linkerServices, final MethodType newType) { |
24719 | 372 |
return replaceMethodsOrThis(linkerServices.asTypeLosslessReturn(invocation, newType), guard == null ? null : |
373 |
Guards.asType(linkerServices, guard, newType)); |
|
374 |
} |
|
375 |
||
376 |
/** |
|
33333 | 377 |
* Changes the type of the invocation, as if |
378 |
* {@link MethodHandle#asType(MethodType)} was applied to its invocation |
|
379 |
* and its guard, if it has one (with return type changed to boolean for |
|
380 |
* guard). If the invocation already is of the required type, returns this |
|
381 |
* object. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
382 |
* @param desc a call descriptor whose method type is adapted. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
383 |
* @return a guarded invocation with the new type applied to it. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
384 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
385 |
public GuardedInvocation asType(final CallSiteDescriptor desc) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
386 |
return asType(desc.getMethodType()); |
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 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
389 |
/** |
33333 | 390 |
* Applies argument filters to both the invocation and the guard (if there |
391 |
* is one) with {@link MethodHandles#filterArguments(MethodHandle, int, MethodHandle...)}. |
|
32534
b3ec7f3b3c2a
8136349: Typos patch for nashorn sources submitted on Sep 10, 2015
sundar
parents:
28785
diff
changeset
|
392 |
* @param pos the position of the first argument being filtered |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
393 |
* @param filters the argument filters |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
394 |
* @return a filtered invocation |
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 filterArguments(final int pos, final MethodHandle... filters) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
397 |
return replaceMethods(MethodHandles.filterArguments(invocation, pos, filters), guard == null ? null : |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
398 |
MethodHandles.filterArguments(guard, pos, filters)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
399 |
} |
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 |
/** |
33333 | 402 |
* Makes an invocation that drops arguments in both the invocation and the |
403 |
* guard (if there is one) with {@link MethodHandles#dropArguments(MethodHandle, int, List)}. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
404 |
* @param pos the position of the first argument being dropped |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
405 |
* @param valueTypes the types of the values being dropped |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
406 |
* @return an invocation that drops arguments |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
407 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
408 |
public GuardedInvocation dropArguments(final int pos, final List<Class<?>> valueTypes) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
409 |
return replaceMethods(MethodHandles.dropArguments(invocation, pos, valueTypes), guard == null ? null : |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
410 |
MethodHandles.dropArguments(guard, pos, valueTypes)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
411 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
412 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
413 |
/** |
33333 | 414 |
* Makes an invocation that drops arguments in both the invocation and the |
415 |
* guard (if there is one) with {@link MethodHandles#dropArguments(MethodHandle, int, Class...)}. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
416 |
* @param pos the position of the first argument being dropped |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
417 |
* @param valueTypes the types of the values being dropped |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
418 |
* @return an invocation that drops arguments |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
419 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
420 |
public GuardedInvocation dropArguments(final int pos, final Class<?>... valueTypes) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
421 |
return replaceMethods(MethodHandles.dropArguments(invocation, pos, valueTypes), guard == null ? null : |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
422 |
MethodHandles.dropArguments(guard, pos, valueTypes)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
423 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
424 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
425 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
426 |
/** |
33333 | 427 |
* Composes the invocation, guard, switch points, and the exception into a |
428 |
* composite method handle that knows how to fall back when the guard fails |
|
429 |
* or the invocation is invalidated. |
|
430 |
* @param fallback the fallback method handle for when a switch point is |
|
431 |
* invalidated, a guard returns false, or invalidating exception is thrown. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
432 |
* @return a composite method handle. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
433 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
434 |
public MethodHandle compose(final MethodHandle fallback) { |
24720 | 435 |
return compose(fallback, fallback, fallback); |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
436 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
437 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
438 |
/** |
33333 | 439 |
* Composes the invocation, guard, switch points, and the exception into a |
440 |
* composite method handle that knows how to fall back when the guard fails |
|
441 |
* or the invocation is invalidated. |
|
442 |
* @param switchpointFallback the fallback method handle in case a switch |
|
443 |
* point is invalidated. |
|
444 |
* @param guardFallback the fallback method handle in case guard returns |
|
445 |
* false. |
|
446 |
* @param catchFallback the fallback method in case the exception handler |
|
447 |
* triggers. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
448 |
* @return a composite method handle. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
449 |
*/ |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
450 |
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
|
451 |
final MethodHandle guarded = |
24720 | 452 |
guard == null ? |
453 |
invocation : |
|
454 |
MethodHandles.guardWithTest( |
|
455 |
guard, |
|
456 |
invocation, |
|
457 |
guardFallback); |
|
458 |
||
459 |
final MethodHandle catchGuarded = |
|
460 |
exception == null ? |
|
461 |
guarded : |
|
33333 | 462 |
MethodHandles.catchException( |
24720 | 463 |
guarded, |
464 |
exception, |
|
465 |
MethodHandles.dropArguments( |
|
466 |
catchFallback, |
|
467 |
0, |
|
468 |
exception)); |
|
469 |
||
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
470 |
if (switchPoints == null) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
471 |
return catchGuarded; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
472 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
473 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
474 |
MethodHandle spGuarded = catchGuarded; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
475 |
for (final SwitchPoint sp : switchPoints) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
476 |
spGuarded = sp.guardWithTest(spGuarded, switchpointFallback); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24720
diff
changeset
|
477 |
} |
24720 | 478 |
|
479 |
return spGuarded; |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
480 |
} |
16245
6a1c6c8bc113
8008371: Fix Dynalink compiler warnings and whitespace
attila
parents:
16234
diff
changeset
|
481 |
} |