001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * https://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.bcel.generic; 020 021import java.io.DataOutputStream; 022import java.io.IOException; 023 024import org.apache.bcel.Const; 025import org.apache.bcel.ExceptionConst; 026 027/** 028 * INVOKESPECIAL - Invoke instance method; special handling for superclass, private and instance initialization method 029 * invocations 030 * 031 * <pre> 032 * Stack: ..., objectref, [arg1, [arg2 ...]] -> ... 033 * </pre> 034 * 035 * @see <a href="https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5.invokespecial"> The 036 * invokespecial instruction in The Java Virtual Machine Specification</a> 037 */ 038public class INVOKESPECIAL extends InvokeInstruction { 039 040 /** 041 * Empty constructor needed for Instruction.readInstruction. Not to be used otherwise. 042 */ 043 INVOKESPECIAL() { 044 } 045 046 /** 047 * Constructs an INVOKESPECIAL instruction. 048 * 049 * @param index index into constant pool. 050 */ 051 public INVOKESPECIAL(final int index) { 052 super(Const.INVOKESPECIAL, index); 053 } 054 055 /** 056 * Call corresponding visitor method(s). The order is: Call visitor methods of implemented interfaces first, then call 057 * methods according to the class hierarchy in descending order, that is, the most specific visitXXX() call comes last. 058 * 059 * @param v Visitor object. 060 */ 061 @Override 062 public void accept(final Visitor v) { 063 v.visitExceptionThrower(this); 064 v.visitTypedInstruction(this); 065 v.visitStackConsumer(this); 066 v.visitStackProducer(this); 067 v.visitLoadClass(this); 068 v.visitCPInstruction(this); 069 v.visitFieldOrMethod(this); 070 v.visitInvokeInstruction(this); 071 v.visitINVOKESPECIAL(this); 072 } 073 074 /** 075 * Dumps instruction as byte code to stream out. 076 * 077 * @param out Output stream. 078 */ 079 @Override 080 public void dump(final DataOutputStream out) throws IOException { 081 out.writeByte(super.getOpcode()); 082 out.writeShort(super.getIndex()); 083 } 084 085 @Override 086 public Class<?>[] getExceptions() { 087 return ExceptionConst.createExceptions(ExceptionConst.EXCS.EXCS_FIELD_AND_METHOD_RESOLUTION, ExceptionConst.NULL_POINTER_EXCEPTION, 088 ExceptionConst.INCOMPATIBLE_CLASS_CHANGE_ERROR, ExceptionConst.ABSTRACT_METHOD_ERROR, ExceptionConst.UNSATISFIED_LINK_ERROR); 089 } 090}