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
39 public final class DynamicFuncCallOp extends AbstractOp {
40 private final CodeType resultType;
41 private final String funcName;
42 private final DirectMethodHandleDesc bootstrapMethod;
43 private final String invocationName;
44 private final MethodTypeDesc invocationType;
45 private final MethodTypeDesc interfaceMethodType;
46 private final MethodTypeDesc dynamicMethodType;
47
48 public DynamicFuncCallOp(CodeType resultType,
49 List<Value> operands,
50 String funcName,
51 DirectMethodHandleDesc bootstrapMethod,
52 String invocationName,
53 MethodTypeDesc invocationType,
54 MethodTypeDesc interfaceMethodType,
55 MethodTypeDesc dynamicMethodType) {
56 super(operands);
57 this.resultType = resultType;
58 this.funcName = funcName;
59 this.bootstrapMethod = bootstrapMethod;
60 this.invocationName = invocationName;
61 this.invocationType = invocationType;
62 this.interfaceMethodType = interfaceMethodType;
63 this.dynamicMethodType = dynamicMethodType;
64 }
65
66 DynamicFuncCallOp(DynamicFuncCallOp that, CodeContext cc) {
67 super(that, cc);
68 this.resultType = that.resultType;
69 this.funcName = that.funcName;
70 this.bootstrapMethod = that.bootstrapMethod;
71 this.invocationName = that.invocationName;
72 this.invocationType = that.invocationType;
73 this.interfaceMethodType = that.interfaceMethodType;
74 this.dynamicMethodType = that.dynamicMethodType;
75 }
76
77 @Override
78 public DynamicFuncCallOp transform(CodeContext cc, CodeTransformer ct) {
79 return new DynamicFuncCallOp(this, cc);
80 }
81
82 @Override
83 public CodeType resultType() {
84 return resultType;
85 }
86
87 @Override
88 public Map<String, Object> externalize() {
89 // for debug print
90 LinkedHashMap<String, Object> attributes = new LinkedHashMap<>();
91 attributes.put("func", funcName);
92 attributes.put("bootstrap", bootstrapMethod);
93 attributes.put("invocationName", invocationName);
94 attributes.put("invocationType", invocationType);
95 attributes.put("interfaceMethodType", interfaceMethodType);
96 attributes.put("dynamicMethodType", dynamicMethodType);
97 return attributes;
98 }
99
100 public String funcName() {
101 return funcName;
102 }
103
104 public DirectMethodHandleDesc bootstrapMethod() {
105 return bootstrapMethod;
106 }
107
108 public String invocationName() {
109 return invocationName;
110 }
111
112 public MethodTypeDesc invocationType() {
113 return invocationType;
114 }
115
116 public MethodTypeDesc interfaceMethodType() {
117 return interfaceMethodType;
118 }
119
120 public MethodTypeDesc dynamicMethodType() {
121 return dynamicMethodType;
122 }
123 }