1 /*
2 * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
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 package jdk.incubator.code.bytecode.impl;
26
27 import java.lang.constant.DirectMethodHandleDesc;
28 import java.lang.constant.MethodTypeDesc;
29 import java.util.LinkedHashMap;
30 import java.util.List;
31 import java.util.Map;
32
33 import jdk.incubator.code.AbstractOp;
34 import jdk.incubator.code.CodeContext;
35 import jdk.incubator.code.CodeTransformer;
36 import jdk.incubator.code.CodeType;
37 import jdk.incubator.code.Value;
38 import jdk.incubator.code.extern.ExternalizedOp;
39
40 public final class DynamicFuncCallOp extends AbstractOp implements ExternalizedOp.Externalizable {
41 private final CodeType resultType;
42 private final String funcName;
43 private final DirectMethodHandleDesc bootstrapMethod;
44 private final String invocationName;
45 private final MethodTypeDesc invocationType;
46 private final MethodTypeDesc interfaceMethodType;
47 private final MethodTypeDesc dynamicMethodType;
48
49 public DynamicFuncCallOp(CodeType resultType,
50 List<Value> operands,
51 String funcName,
52 DirectMethodHandleDesc bootstrapMethod,
53 String invocationName,
54 MethodTypeDesc invocationType,
55 MethodTypeDesc interfaceMethodType,
56 MethodTypeDesc dynamicMethodType) {
57 super(operands);
58 this.resultType = resultType;
59 this.funcName = funcName;
60 this.bootstrapMethod = bootstrapMethod;
61 this.invocationName = invocationName;
62 this.invocationType = invocationType;
63 this.interfaceMethodType = interfaceMethodType;
64 this.dynamicMethodType = dynamicMethodType;
65 }
66
67 DynamicFuncCallOp(DynamicFuncCallOp that, CodeContext cc) {
68 super(that, cc);
69 this.resultType = that.resultType;
70 this.funcName = that.funcName;
71 this.bootstrapMethod = that.bootstrapMethod;
72 this.invocationName = that.invocationName;
73 this.invocationType = that.invocationType;
74 this.interfaceMethodType = that.interfaceMethodType;
75 this.dynamicMethodType = that.dynamicMethodType;
76 }
77
78 @Override
79 public DynamicFuncCallOp transform(CodeContext cc, CodeTransformer ct) {
80 return new DynamicFuncCallOp(this, cc);
81 }
82
83 @Override
84 public CodeType resultType() {
85 return resultType;
86 }
87
88 @Override
89 public Map<String, Object> externalize() {
90 // for debug print
91 LinkedHashMap<String, Object> attributes = new LinkedHashMap<>();
92 attributes.put("func", funcName);
93 attributes.put("bootstrap", bootstrapMethod);
94 attributes.put("invocationName", invocationName);
95 attributes.put("invocationType", invocationType);
96 attributes.put("interfaceMethodType", interfaceMethodType);
97 attributes.put("dynamicMethodType", dynamicMethodType);
98 return attributes;
99 }
100
101 public String funcName() {
102 return funcName;
103 }
104
105 public DirectMethodHandleDesc bootstrapMethod() {
106 return bootstrapMethod;
107 }
108
109 public String invocationName() {
110 return invocationName;
111 }
112
113 public MethodTypeDesc invocationType() {
114 return invocationType;
115 }
116
117 public MethodTypeDesc interfaceMethodType() {
118 return interfaceMethodType;
119 }
120
121 public MethodTypeDesc dynamicMethodType() {
122 return dynamicMethodType;
123 }
124 }