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 java.lang.classfile.TypeKind;
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 /**
1145 resolvedHandle = DirectMethodHandle.make(member);
1146 }
1147 }
1148
1149 @Override
1150 public boolean equals(Object other) {
1151 if (this == other) return true;
1152 if (other == null) return false;
1153 return (other instanceof NamedFunction that)
1154 && this.member != null
1155 && this.member.equals(that.member);
1156 }
1157
1158 @Override
1159 public int hashCode() {
1160 if (member != null)
1161 return member.hashCode();
1162 return super.hashCode();
1163 }
1164
1165 static final MethodType INVOKER_METHOD_TYPE =
1166 MethodType.methodType(Object.class, MethodHandle.class, Object[].class);
1167
1168 private static MethodHandle computeInvoker(MethodTypeForm typeForm) {
1169 typeForm = typeForm.basicType().form(); // normalize to basic type
1170 MethodHandle mh = typeForm.cachedMethodHandle(MethodTypeForm.MH_NF_INV);
1171 if (mh != null) return mh;
1172 MemberName invoker = InvokerBytecodeGenerator.generateNamedFunctionInvoker(typeForm); // this could take a while
1173 mh = DirectMethodHandle.make(invoker);
1174 MethodHandle mh2 = typeForm.cachedMethodHandle(MethodTypeForm.MH_NF_INV);
1175 if (mh2 != null) return mh2; // benign race
1176 if (!mh.type().equals(INVOKER_METHOD_TYPE))
1177 throw newInternalError(mh.debugString());
1178 return typeForm.setCachedMethodHandle(MethodTypeForm.MH_NF_INV, mh);
1179 }
1180
1181 @Hidden
1182 Object invokeWithArguments(Object... arguments) throws Throwable {
1183 // If we have a cached invoker, call it right away.
1184 // NOTE: The invoker always returns a reference value.
1185 if (TRACE_INTERPRETER) return invokeWithArgumentsTracing(arguments);
1186 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 java.lang.classfile.TypeKind;
30 import jdk.internal.perf.PerfCounter;
31 import jdk.internal.vm.annotation.DontInline;
32 import jdk.internal.vm.annotation.Hidden;
33 import jdk.internal.vm.annotation.Stable;
34 import sun.invoke.util.Wrapper;
35
36 import java.lang.annotation.ElementType;
37 import java.lang.annotation.Retention;
38 import java.lang.annotation.RetentionPolicy;
39 import java.lang.annotation.Target;
40 import java.lang.reflect.Method;
41 import java.util.Arrays;
42 import java.util.HashMap;
43
44 import static java.lang.invoke.LambdaForm.BasicType.*;
45 import static java.lang.invoke.MethodHandleNatives.Constants.*;
46 import static java.lang.invoke.MethodHandleStatics.*;
47
48 /**
1146 resolvedHandle = DirectMethodHandle.make(member);
1147 }
1148 }
1149
1150 @Override
1151 public boolean equals(Object other) {
1152 if (this == other) return true;
1153 if (other == null) return false;
1154 return (other instanceof NamedFunction that)
1155 && this.member != null
1156 && this.member.equals(that.member);
1157 }
1158
1159 @Override
1160 public int hashCode() {
1161 if (member != null)
1162 return member.hashCode();
1163 return super.hashCode();
1164 }
1165
1166 static final MethodType INVOKER_METHOD_TYPE;
1167 private static @Stable MethodType[] archivedObjects;
1168
1169 static {
1170 CDS.initializeFromArchive(NamedFunction.class);
1171 if (archivedObjects != null) {
1172 INVOKER_METHOD_TYPE = archivedObjects[0];
1173 } else {
1174 INVOKER_METHOD_TYPE =
1175 MethodType.methodType(Object.class, MethodHandle.class, Object[].class);
1176 }
1177 }
1178
1179 static void dumpSharedArchive() {
1180 archivedObjects = new MethodType[1];
1181 archivedObjects[0] = INVOKER_METHOD_TYPE;
1182 }
1183
1184 private static MethodHandle computeInvoker(MethodTypeForm typeForm) {
1185 typeForm = typeForm.basicType().form(); // normalize to basic type
1186 MethodHandle mh = typeForm.cachedMethodHandle(MethodTypeForm.MH_NF_INV);
1187 if (mh != null) return mh;
1188 MemberName invoker = InvokerBytecodeGenerator.generateNamedFunctionInvoker(typeForm); // this could take a while
1189 mh = DirectMethodHandle.make(invoker);
1190 MethodHandle mh2 = typeForm.cachedMethodHandle(MethodTypeForm.MH_NF_INV);
1191 if (mh2 != null) return mh2; // benign race
1192 if (!mh.type().equals(INVOKER_METHOD_TYPE))
1193 throw newInternalError(mh.debugString());
1194 return typeForm.setCachedMethodHandle(MethodTypeForm.MH_NF_INV, mh);
1195 }
1196
1197 @Hidden
1198 Object invokeWithArguments(Object... arguments) throws Throwable {
1199 // If we have a cached invoker, call it right away.
1200 // NOTE: The invoker always returns a reference value.
1201 if (TRACE_INTERPRETER) return invokeWithArgumentsTracing(arguments);
1202 return invoker().invokeBasic(resolvedHandle(), arguments);
|