jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/MethodImpl.java
changeset 45714 1820d351198d
parent 42676 36fa143f8de8
equal deleted inserted replaced
45713:ee3f2cbfe23a 45714:1820d351198d
     1 /*
     1 /*
     2  * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package com.sun.tools.jdi;
    26 package com.sun.tools.jdi;
    27 
    27 
    28 import com.sun.jdi.*;
    28 import java.util.ArrayList;
    29 
       
    30 import java.util.List;
    29 import java.util.List;
    31 import java.util.Iterator;
    30 
    32 import java.util.ArrayList;
    31 import com.sun.jdi.AbsentInformationException;
    33 import java.util.Comparator;
    32 import com.sun.jdi.ArrayReference;
       
    33 import com.sun.jdi.ArrayType;
       
    34 import com.sun.jdi.ClassNotLoadedException;
       
    35 import com.sun.jdi.InterfaceType;
       
    36 import com.sun.jdi.InvalidTypeException;
       
    37 import com.sun.jdi.Location;
       
    38 import com.sun.jdi.Method;
       
    39 import com.sun.jdi.Type;
       
    40 import com.sun.jdi.Value;
       
    41 import com.sun.jdi.VirtualMachine;
    34 
    42 
    35 public abstract class MethodImpl extends TypeComponentImpl
    43 public abstract class MethodImpl extends TypeComponentImpl
    36     implements Method {
    44                                  implements Method
       
    45 {
    37     private JNITypeParser signatureParser;
    46     private JNITypeParser signatureParser;
       
    47 
    38     abstract int argSlotCount() throws AbsentInformationException;
    48     abstract int argSlotCount() throws AbsentInformationException;
    39 
    49 
    40     abstract List<Location> allLineLocations(SDE.Stratum stratum,
    50     abstract List<Location> allLineLocations(SDE.Stratum stratum,
    41                                    String sourceName)
    51                                              String sourceName)
    42                            throws AbsentInformationException;
    52                             throws AbsentInformationException;
    43 
    53 
    44     abstract List<Location> locationsOfLine(SDE.Stratum stratum,
    54     abstract List<Location> locationsOfLine(SDE.Stratum stratum,
    45                                   String sourceName,
    55                                             String sourceName,
    46                                   int lineNumber)
    56                                             int lineNumber)
    47                            throws AbsentInformationException;
    57                             throws AbsentInformationException;
    48 
    58 
    49     MethodImpl(VirtualMachine vm, ReferenceTypeImpl declaringType,
    59     MethodImpl(VirtualMachine vm, ReferenceTypeImpl declaringType,
    50                long ref,
    60                long ref, String name, String signature,
    51                String name, String signature,
       
    52                String genericSignature, int modifiers) {
    61                String genericSignature, int modifiers) {
    53         super(vm, declaringType, ref, name, signature,
    62         super(vm, declaringType, ref, name, signature,
    54               genericSignature, modifiers);
    63               genericSignature, modifiers);
    55         signatureParser = new JNITypeParser(signature);
    64         signatureParser = new JNITypeParser(signature);
    56     }
    65     }
    60                                        long ref,
    69                                        long ref,
    61                                        String name,
    70                                        String name,
    62                                        String signature,
    71                                        String signature,
    63                                        String genericSignature,
    72                                        String genericSignature,
    64                                        int modifiers) {
    73                                        int modifiers) {
    65         if ((modifiers &
    74         if ((modifiers & (VMModifiers.NATIVE | VMModifiers.ABSTRACT)) != 0) {
    66              (VMModifiers.NATIVE | VMModifiers.ABSTRACT)) != 0) {
       
    67             return new NonConcreteMethodImpl(vm, declaringType, ref,
    75             return new NonConcreteMethodImpl(vm, declaringType, ref,
    68                                              name, signature,
    76                                              name, signature,
    69                                              genericSignature,
    77                                              genericSignature,
    70                                              modifiers);
    78                                              modifiers);
    71         } else {
    79         } else {
    90     public int hashCode() {
    98     public int hashCode() {
    91         return (int)ref();
    99         return (int)ref();
    92     }
   100     }
    93 
   101 
    94     public final List<Location> allLineLocations()
   102     public final List<Location> allLineLocations()
    95                            throws AbsentInformationException {
   103                                 throws AbsentInformationException {
    96         return allLineLocations(vm.getDefaultStratum(), null);
   104         return allLineLocations(vm.getDefaultStratum(), null);
    97     }
   105     }
    98 
   106 
    99     public List<Location> allLineLocations(String stratumID,
   107     public List<Location> allLineLocations(String stratumID,
   100                                  String sourceName)
   108                                            String sourceName)
   101                            throws AbsentInformationException {
   109                           throws AbsentInformationException {
   102         return allLineLocations(declaringType.stratum(stratumID),
   110         return allLineLocations(declaringType.stratum(stratumID), sourceName);
   103                                 sourceName);
       
   104     }
   111     }
   105 
   112 
   106     public final List<Location> locationsOfLine(int lineNumber)
   113     public final List<Location> locationsOfLine(int lineNumber)
   107                            throws AbsentInformationException {
   114                                 throws AbsentInformationException {
   108         return locationsOfLine(vm.getDefaultStratum(),
   115         return locationsOfLine(vm.getDefaultStratum(),
   109                                null, lineNumber);
   116                                null, lineNumber);
   110     }
   117     }
   111 
   118 
   112     public List<Location> locationsOfLine(String stratumID,
   119     public List<Location> locationsOfLine(String stratumID,
   113                                 String sourceName,
   120                                           String sourceName,
   114                                 int lineNumber)
   121                                           int lineNumber)
   115                            throws AbsentInformationException {
   122                           throws AbsentInformationException {
   116         return locationsOfLine(declaringType.stratum(stratumID),
   123         return locationsOfLine(declaringType.stratum(stratumID),
   117                                sourceName, lineNumber);
   124                                sourceName, lineNumber);
   118     }
   125     }
   119 
   126 
   120     LineInfo codeIndexToLineInfo(SDE.Stratum stratum,
   127     LineInfo codeIndexToLineInfo(SDE.Stratum stratum,
   121                                  long codeIndex) {
   128                                  long codeIndex) {
   122         if (stratum.isJava()) {
   129         if (stratum.isJava()) {
   123             return new BaseLineInfo(-1, declaringType);
   130             return new BaseLineInfo(-1, declaringType);
   124         } else {
   131         } else {
   125             return new StratumLineInfo(stratum.id(), -1,
   132             return new StratumLineInfo(stratum.id(), -1, null, null);
   126                                        null, null);
       
   127         }
   133         }
   128     }
   134     }
   129 
   135 
   130     /**
   136     /**
   131      * @return a text representation of the declared return type
   137      * @return a text representation of the declared return type
   162         return enclosing.findType(signature);
   168         return enclosing.findType(signature);
   163     }
   169     }
   164 
   170 
   165     public List<Type> argumentTypes() throws ClassNotLoadedException {
   171     public List<Type> argumentTypes() throws ClassNotLoadedException {
   166         int size = argumentSignatures().size();
   172         int size = argumentSignatures().size();
   167         ArrayList<Type> types = new ArrayList<Type>(size);
   173         List<Type> types = new ArrayList<>(size);
   168         for (int i = 0; i < size; i++) {
   174         for (int i = 0; i < size; i++) {
   169             Type type = argumentType(i);
   175             Type type = argumentType(i);
   170             types.add(type);
   176             types.add(type);
   171         }
   177         }
   172 
   178 
   175 
   181 
   176     public int compareTo(Method method) {
   182     public int compareTo(Method method) {
   177         ReferenceTypeImpl declaringType = (ReferenceTypeImpl)declaringType();
   183         ReferenceTypeImpl declaringType = (ReferenceTypeImpl)declaringType();
   178         int rc = declaringType.compareTo(method.declaringType());
   184         int rc = declaringType.compareTo(method.declaringType());
   179         if (rc == 0) {
   185         if (rc == 0) {
   180             rc = declaringType.indexOf(this) -
   186             rc = declaringType.indexOf(this) - declaringType.indexOf(method);
   181                     declaringType.indexOf(method);
       
   182         }
   187         }
   183         return rc;
   188         return rc;
   184     }
   189     }
   185 
   190 
   186     public boolean isAbstract() {
   191     public boolean isAbstract() {
   224                                     declaringType, ref).isObsolete;
   229                                     declaringType, ref).isObsolete;
   225         } catch (JDWPException exc) {
   230         } catch (JDWPException exc) {
   226             throw exc.toJDIException();
   231             throw exc.toJDIException();
   227         }
   232         }
   228     }
   233     }
   229 
       
   230 
   234 
   231     /*
   235     /*
   232      * A container class for the return value to allow
   236      * A container class for the return value to allow
   233      * proper type-checking.
   237      * proper type-checking.
   234      */
   238      */
   298      */
   302      */
   299     void handleVarArgs(List<Value> arguments)
   303     void handleVarArgs(List<Value> arguments)
   300         throws ClassNotLoadedException, InvalidTypeException {
   304         throws ClassNotLoadedException, InvalidTypeException {
   301         List<Type> paramTypes = this.argumentTypes();
   305         List<Type> paramTypes = this.argumentTypes();
   302         ArrayType lastParamType = (ArrayType)paramTypes.get(paramTypes.size() - 1);
   306         ArrayType lastParamType = (ArrayType)paramTypes.get(paramTypes.size() - 1);
   303         Type componentType = lastParamType.componentType();
       
   304         int argCount = arguments.size();
   307         int argCount = arguments.size();
   305         int paramCount = paramTypes.size();
   308         int paramCount = paramTypes.size();
   306         if (argCount < paramCount - 1) {
   309         if (argCount < paramCount - 1) {
   307             // Error; will be caught later.
   310             // Error; will be caught later.
   308             return;
   311             return;
   363      * The output list will be different than the input list.
   366      * The output list will be different than the input list.
   364      */
   367      */
   365     List<Value> validateAndPrepareArgumentsForInvoke(List<? extends Value> origArguments)
   368     List<Value> validateAndPrepareArgumentsForInvoke(List<? extends Value> origArguments)
   366                          throws ClassNotLoadedException, InvalidTypeException {
   369                          throws ClassNotLoadedException, InvalidTypeException {
   367 
   370 
   368         List<Value> arguments = new ArrayList<Value>(origArguments);
   371         List<Value> arguments = new ArrayList<>(origArguments);
   369         if (isVarArgs()) {
   372         if (isVarArgs()) {
   370             handleVarArgs(arguments);
   373             handleVarArgs(arguments);
   371         }
   374         }
   372 
   375 
   373         int argSize = arguments.size();
   376         int argSize = arguments.size();