author | joehw |
Wed, 26 Jun 2019 05:49:59 +0000 | |
changeset 55496 | 8e0ae3830fca |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
6 | 1 |
/* |
55496 | 2 |
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
6 | 3 |
*/ |
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
4 |
/* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
5 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
6 |
* contributor license agreements. See the NOTICE file distributed with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
7 |
* this work for additional information regarding copyright ownership. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
8 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
9 |
* (the "License"); you may not use this file except in compliance with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
10 |
* the License. You may obtain a copy of the License at |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
11 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
13 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
14 |
* Unless required by applicable law or agreed to in writing, software |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS, |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
17 |
* See the License for the specific language governing permissions and |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
18 |
* limitations under the License. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
19 |
*/ |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
20 |
|
6 | 21 |
package com.sun.org.apache.bcel.internal.generic; |
22 |
||
23 |
import java.util.StringTokenizer; |
|
24 |
||
46174 | 25 |
import com.sun.org.apache.bcel.internal.Const; |
26 |
import com.sun.org.apache.bcel.internal.classfile.Constant; |
|
27 |
import com.sun.org.apache.bcel.internal.classfile.ConstantCP; |
|
28 |
import com.sun.org.apache.bcel.internal.classfile.ConstantPool; |
|
29 |
||
6 | 30 |
/** |
31 |
* Super class for the INVOKExxx family of instructions. |
|
32 |
* |
|
55496 | 33 |
* @version $Id$ |
34 |
* @LastModified: Jun 2019 |
|
6 | 35 |
*/ |
46174 | 36 |
public abstract class InvokeInstruction extends FieldOrMethod implements ExceptionThrower, |
37 |
StackConsumer, StackProducer { |
|
6 | 38 |
|
46174 | 39 |
/** |
55496 | 40 |
* Empty constructor needed for Instruction.readInstruction. |
41 |
* Not to be used otherwise. |
|
46174 | 42 |
*/ |
43 |
InvokeInstruction() { |
|
44 |
} |
|
45 |
||
46 |
||
47 |
/** |
|
48 |
* @param index to constant pool |
|
49 |
*/ |
|
50 |
protected InvokeInstruction(final short opcode, final int index) { |
|
51 |
super(opcode, index); |
|
52 |
} |
|
53 |
||
6 | 54 |
|
46174 | 55 |
/** |
56 |
* @return mnemonic for instruction with symbolic references resolved |
|
57 |
*/ |
|
58 |
@Override |
|
59 |
public String toString( final ConstantPool cp ) { |
|
60 |
final Constant c = cp.getConstant(super.getIndex()); |
|
61 |
final StringTokenizer tok = new StringTokenizer(cp.constantToString(c)); |
|
62 |
return Const.getOpcodeName(super.getOpcode()) + " " + tok.nextToken().replace('.', '/') |
|
63 |
+ tok.nextToken(); |
|
64 |
} |
|
65 |
||
6 | 66 |
|
46174 | 67 |
/** |
68 |
* Also works for instructions whose stack effect depends on the |
|
69 |
* constant pool entry they reference. |
|
70 |
* @return Number of words consumed from stack by this instruction |
|
71 |
*/ |
|
72 |
@Override |
|
73 |
public int consumeStack( final ConstantPoolGen cpg ) { |
|
74 |
int sum; |
|
75 |
if ((super.getOpcode() == Const.INVOKESTATIC) || (super.getOpcode() == Const.INVOKEDYNAMIC)) { |
|
76 |
sum = 0; |
|
77 |
} else { |
|
78 |
sum = 1; // this reference |
|
79 |
} |
|
6 | 80 |
|
46174 | 81 |
final String signature = getSignature(cpg); |
82 |
sum += Type.getArgumentTypesSize(signature); |
|
83 |
return sum; |
|
84 |
} |
|
85 |
||
6 | 86 |
|
46174 | 87 |
/** |
88 |
* Also works for instructions whose stack effect depends on the |
|
89 |
* constant pool entry they reference. |
|
90 |
* @return Number of words produced onto stack by this instruction |
|
91 |
*/ |
|
92 |
@Override |
|
93 |
public int produceStack( final ConstantPoolGen cpg ) { |
|
94 |
final String signature = getSignature(cpg); |
|
95 |
return Type.getReturnTypeSize(signature); |
|
96 |
} |
|
6 | 97 |
|
46174 | 98 |
/** |
99 |
* This overrides the deprecated version as we know here that the referenced class |
|
100 |
* may legally be an array. |
|
101 |
* |
|
102 |
* @deprecated in FieldOrMethod |
|
103 |
* |
|
104 |
* @return name of the referenced class/interface |
|
105 |
* @throws IllegalArgumentException if the referenced class is an array (this should not happen) |
|
106 |
*/ |
|
107 |
@Override |
|
108 |
@Deprecated |
|
109 |
public String getClassName( final ConstantPoolGen cpg ) { |
|
110 |
final ConstantPool cp = cpg.getConstantPool(); |
|
111 |
final ConstantCP cmr = (ConstantCP) cp.getConstant(super.getIndex()); |
|
112 |
final String className = cp.getConstantString(cmr.getClassIndex(), Const.CONSTANT_Class); |
|
113 |
return className.replace('/', '.'); |
|
114 |
} |
|
6 | 115 |
|
46174 | 116 |
/** @return return type of referenced method. |
117 |
*/ |
|
118 |
@Override |
|
119 |
public Type getType( final ConstantPoolGen cpg ) { |
|
120 |
return getReturnType(cpg); |
|
121 |
} |
|
6 | 122 |
|
46174 | 123 |
|
124 |
/** @return name of referenced method. |
|
125 |
*/ |
|
126 |
public String getMethodName( final ConstantPoolGen cpg ) { |
|
127 |
return getName(cpg); |
|
128 |
} |
|
129 |
||
6 | 130 |
|
46174 | 131 |
/** @return return type of referenced method. |
132 |
*/ |
|
133 |
public Type getReturnType( final ConstantPoolGen cpg ) { |
|
134 |
return Type.getReturnType(getSignature(cpg)); |
|
135 |
} |
|
136 |
||
6 | 137 |
|
46174 | 138 |
/** @return argument types of referenced method. |
139 |
*/ |
|
140 |
public Type[] getArgumentTypes( final ConstantPoolGen cpg ) { |
|
141 |
return Type.getArgumentTypes(getSignature(cpg)); |
|
142 |
} |
|
143 |
||
6 | 144 |
} |