8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.lang.invoke;
27
28 import jdk.internal.perf.PerfCounter;
29 import jdk.internal.vm.annotation.DontInline;
30 import jdk.internal.vm.annotation.Hidden;
31 import jdk.internal.vm.annotation.Stable;
32 import sun.invoke.util.Wrapper;
33
34 import java.lang.annotation.ElementType;
35 import java.lang.annotation.Retention;
36 import java.lang.annotation.RetentionPolicy;
37 import java.lang.annotation.Target;
38 import java.lang.reflect.Method;
39 import java.util.Arrays;
40 import java.util.HashMap;
41
42 import static java.lang.invoke.LambdaForm.BasicType.*;
43 import static java.lang.invoke.MethodHandleNatives.Constants.*;
44 import static java.lang.invoke.MethodHandleStatics.*;
45
46 /**
47 * The symbolic, non-executable form of a method handle's invocation semantics.
1139 resolvedHandle = DirectMethodHandle.make(member);
1140 }
1141 }
1142
1143 @Override
1144 public boolean equals(Object other) {
1145 if (this == other) return true;
1146 if (other == null) return false;
1147 return (other instanceof NamedFunction that)
1148 && this.member != null
1149 && this.member.equals(that.member);
1150 }
1151
1152 @Override
1153 public int hashCode() {
1154 if (member != null)
1155 return member.hashCode();
1156 return super.hashCode();
1157 }
1158
1159 static final MethodType INVOKER_METHOD_TYPE =
1160 MethodType.methodType(Object.class, MethodHandle.class, Object[].class);
1161
1162 private static MethodHandle computeInvoker(MethodTypeForm typeForm) {
1163 typeForm = typeForm.basicType().form(); // normalize to basic type
1164 MethodHandle mh = typeForm.cachedMethodHandle(MethodTypeForm.MH_NF_INV);
1165 if (mh != null) return mh;
1166 MemberName invoker = InvokerBytecodeGenerator.generateNamedFunctionInvoker(typeForm); // this could take a while
1167 mh = DirectMethodHandle.make(invoker);
1168 MethodHandle mh2 = typeForm.cachedMethodHandle(MethodTypeForm.MH_NF_INV);
1169 if (mh2 != null) return mh2; // benign race
1170 if (!mh.type().equals(INVOKER_METHOD_TYPE))
1171 throw newInternalError(mh.debugString());
1172 return typeForm.setCachedMethodHandle(MethodTypeForm.MH_NF_INV, mh);
1173 }
1174
1175 @Hidden
1176 Object invokeWithArguments(Object... arguments) throws Throwable {
1177 // If we have a cached invoker, call it right away.
1178 // NOTE: The invoker always returns a reference value.
1179 if (TRACE_INTERPRETER) return invokeWithArgumentsTracing(arguments);
1180 return invoker().invokeBasic(resolvedHandle(), arguments);
|
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.lang.invoke;
27
28 import jdk.internal.misc.CDS;
29 import jdk.internal.perf.PerfCounter;
30 import jdk.internal.vm.annotation.DontInline;
31 import jdk.internal.vm.annotation.Hidden;
32 import jdk.internal.vm.annotation.Stable;
33 import sun.invoke.util.Wrapper;
34
35 import java.lang.annotation.ElementType;
36 import java.lang.annotation.Retention;
37 import java.lang.annotation.RetentionPolicy;
38 import java.lang.annotation.Target;
39 import java.lang.reflect.Method;
40 import java.util.Arrays;
41 import java.util.HashMap;
42
43 import static java.lang.invoke.LambdaForm.BasicType.*;
44 import static java.lang.invoke.MethodHandleNatives.Constants.*;
45 import static java.lang.invoke.MethodHandleStatics.*;
46
47 /**
48 * The symbolic, non-executable form of a method handle's invocation semantics.
1140 resolvedHandle = DirectMethodHandle.make(member);
1141 }
1142 }
1143
1144 @Override
1145 public boolean equals(Object other) {
1146 if (this == other) return true;
1147 if (other == null) return false;
1148 return (other instanceof NamedFunction that)
1149 && this.member != null
1150 && this.member.equals(that.member);
1151 }
1152
1153 @Override
1154 public int hashCode() {
1155 if (member != null)
1156 return member.hashCode();
1157 return super.hashCode();
1158 }
1159
1160 static final MethodType INVOKER_METHOD_TYPE;
1161 private static @Stable MethodType[] archivedObjects;
1162
1163 static {
1164 CDS.initializeFromArchive(NamedFunction.class);
1165 if (archivedObjects != null) {
1166 INVOKER_METHOD_TYPE = archivedObjects[0];
1167 } else {
1168 INVOKER_METHOD_TYPE =
1169 MethodType.methodType(Object.class, MethodHandle.class, Object[].class);
1170 }
1171 }
1172
1173 static void dumpSharedArchive() {
1174 archivedObjects = new MethodType[1];
1175 archivedObjects[0] = INVOKER_METHOD_TYPE;
1176 }
1177
1178 private static MethodHandle computeInvoker(MethodTypeForm typeForm) {
1179 typeForm = typeForm.basicType().form(); // normalize to basic type
1180 MethodHandle mh = typeForm.cachedMethodHandle(MethodTypeForm.MH_NF_INV);
1181 if (mh != null) return mh;
1182 MemberName invoker = InvokerBytecodeGenerator.generateNamedFunctionInvoker(typeForm); // this could take a while
1183 mh = DirectMethodHandle.make(invoker);
1184 MethodHandle mh2 = typeForm.cachedMethodHandle(MethodTypeForm.MH_NF_INV);
1185 if (mh2 != null) return mh2; // benign race
1186 if (!mh.type().equals(INVOKER_METHOD_TYPE))
1187 throw newInternalError(mh.debugString());
1188 return typeForm.setCachedMethodHandle(MethodTypeForm.MH_NF_INV, mh);
1189 }
1190
1191 @Hidden
1192 Object invokeWithArguments(Object... arguments) throws Throwable {
1193 // If we have a cached invoker, call it right away.
1194 // NOTE: The invoker always returns a reference value.
1195 if (TRACE_INTERPRETER) return invokeWithArgumentsTracing(arguments);
1196 return invoker().invokeBasic(resolvedHandle(), arguments);
|