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