jdk/src/share/classes/com/sun/tools/jdi/ConcreteMethodImpl.java
author prr
Tue, 15 Jul 2014 11:22:14 -0700
changeset 25522 10d789df41bb
parent 14342 8435a30053c1
permissions -rw-r--r--
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes Reviewed-by: psandoz, prr Contributed-by: otaviopolianasantana@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 11277
diff changeset
     2
 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.jdi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.ListIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.lang.ref.SoftReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Represents methods with method bodies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * That is, non-native non-abstract methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Private to MethodImpl.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class ConcreteMethodImpl extends MethodImpl {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * A subset of the line number info that is softly cached
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static private class SoftLocationXRefs {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        final String stratumID;   // The stratum of this information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        final Map<Integer, List<Location>> lineMapper;     // Maps line number to location(s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        final List<Location> lineLocations; // List of locations ordered by code index
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
         * Note: these do not necessarily correspond to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
         * the line numbers of the first and last elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
         * in the lineLocations list. Use these only for bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
         * checking and with lineMapper.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        final int lowestLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        final int highestLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        SoftLocationXRefs(String stratumID, Map<Integer, List<Location>> lineMapper, List<Location> lineLocations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                     int lowestLine, int highestLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            this.stratumID = stratumID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            this.lineMapper = Collections.unmodifiableMap(lineMapper);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            this.lineLocations =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                Collections.unmodifiableList(lineLocations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            this.lowestLine = lowestLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            this.highestLine = highestLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private Location location = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private SoftReference<SoftLocationXRefs> softBaseLocationXRefsRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private SoftReference<SoftLocationXRefs> softOtherLocationXRefsRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private SoftReference<List<LocalVariable>> variablesRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private boolean absentVariableInformation = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private long firstIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private long lastIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private SoftReference<byte[]> bytecodesRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private int argSlotCount = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    ConcreteMethodImpl(VirtualMachine vm, ReferenceTypeImpl declaringType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                       long ref,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                       String name, String signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                       String genericSignature, int modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        // The generic signature is set when this is created
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        super(vm, declaringType, ref, name, signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
              genericSignature, modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public Location location() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (location == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            getBaseLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    List<Location> sourceNameFilter(List<Location> list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                          SDE.Stratum stratum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                          String sourceName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                            throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (sourceName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            return list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            /* needs sourceName filteration */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            List<Location> locs = new ArrayList<Location>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            for (Location loc : list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                if (((LocationImpl)loc).sourceName(stratum).equals(sourceName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    locs.add(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            return locs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    List<Location> allLineLocations(SDE.Stratum stratum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                          String sourceName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                            throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        List<Location> lineLocations = getLocations(stratum).lineLocations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (lineLocations.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            throw new AbsentInformationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return Collections.unmodifiableList(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
          sourceNameFilter(lineLocations, stratum, sourceName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    List<Location> locationsOfLine(SDE.Stratum stratum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                         String sourceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                         int lineNumber)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                            throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        SoftLocationXRefs info = getLocations(stratum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (info.lineLocations.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            throw new AbsentInformationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
         * Find the locations which match the line number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         * passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         */
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 14342
diff changeset
   146
        List<Location> list = info.lineMapper.get(lineNumber);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        if (list == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            list = new ArrayList<Location>(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        return Collections.unmodifiableList(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
          sourceNameFilter(list, stratum, sourceName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public Location locationOfCodeIndex(long codeIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (firstIndex == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            getBaseLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         * Check for invalid code index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (codeIndex < firstIndex || codeIndex > lastIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return new LocationImpl(virtualMachine(), this, codeIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    LineInfo codeIndexToLineInfo(SDE.Stratum stratum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                                 long codeIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (firstIndex == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            getBaseLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
         * Check for invalid code index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (codeIndex < firstIndex || codeIndex > lastIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            throw new InternalError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    "Location with invalid code index");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        List<Location> lineLocations = getLocations(stratum).lineLocations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
         * Check for absent line numbers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (lineLocations.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            return super.codeIndexToLineInfo(stratum, codeIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   195
        Iterator<Location> iter = lineLocations.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
         * Treat code before the beginning of the first line table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
         * entry as part of the first line.  javac will generate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
         * code like this for some local classes. This "prolog"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
         * code contains assignments from locals in the enclosing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
         * scope to synthetic fields in the local class.  Same for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
         * other language prolog code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        LocationImpl bestMatch = (LocationImpl)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            LocationImpl current = (LocationImpl)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            if (current.codeIndex() > codeIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            bestMatch = current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return bestMatch.getLineInfo(stratum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public List<LocalVariable> variables() throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return getVariables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public List<LocalVariable> variablesByName(String name) throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        List<LocalVariable> variables = getVariables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        List<LocalVariable> retList = new ArrayList<LocalVariable>(2);
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   224
        Iterator<LocalVariable> iter = variables.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        while(iter.hasNext()) {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   226
            LocalVariable variable = iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            if (variable.name().equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                retList.add(variable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return retList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public List<LocalVariable> arguments() throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        List<LocalVariable> variables = getVariables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        List<LocalVariable> retList = new ArrayList<LocalVariable>(variables.size());
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   238
        Iterator<LocalVariable> iter = variables.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        while(iter.hasNext()) {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   240
            LocalVariable variable = iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            if (variable.isArgument()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                retList.add(variable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        return retList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public byte[] bytecodes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        byte[] bytecodes = (bytecodesRef == null) ? null :
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   250
                                     bytecodesRef.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (bytecodes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                bytecodes = JDWP.Method.Bytecodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                                 process(vm, declaringType, ref).bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            bytecodesRef = new SoftReference<byte[]>(bytecodes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
         * Arrays are always modifiable, so it is a little unsafe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
         * to return the cached bytecodes directly; instead, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
         * make a clone at the cost of using more memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
         */
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   265
        return bytecodes.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    int argSlotCount() throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (argSlotCount == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            getVariables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return argSlotCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private SoftLocationXRefs getLocations(SDE.Stratum stratum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if (stratum.isJava()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            return getBaseLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        String stratumID = stratum.id();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        SoftLocationXRefs info =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            (softOtherLocationXRefsRef == null) ? null :
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   282
               softOtherLocationXRefsRef.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (info != null && info.stratumID.equals(stratumID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        List<Location> lineLocations = new ArrayList<Location>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        Map<Integer, List<Location>> lineMapper = new HashMap<Integer, List<Location>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        int lowestLine = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        int highestLine = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        SDE.LineStratum lastLineStratum = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        SDE.Stratum baseStratum =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            declaringType.stratum(SDE.BASE_STRATUM_NAME);
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   294
        Iterator<Location> it = getBaseLocations().lineLocations.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        while(it.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            LocationImpl loc = (LocationImpl)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            int baseLineNumber = loc.lineNumber(baseStratum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            SDE.LineStratum lineStratum =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                  stratum.lineStratum(declaringType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                                      baseLineNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            if (lineStratum == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                // location not mapped in this stratum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            int lineNumber = lineStratum.lineNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            // remove unmapped and dup lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            if ((lineNumber != -1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                          (!lineStratum.equals(lastLineStratum))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                lastLineStratum = lineStratum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                // Remember the largest/smallest line number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                if (lineNumber > highestLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    highestLine = lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                if ((lineNumber < lowestLine) || (lowestLine == -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    lowestLine = lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                loc.addStratumLineInfo(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                  new StratumLineInfo(stratumID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                                      lineNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                                      lineStratum.sourceName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                                      lineStratum.sourcePath()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                // Add to the location list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                lineLocations.add(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                // Add to the line -> locations map
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 14342
diff changeset
   332
                Integer key = lineNumber;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                List<Location> mappedLocs = lineMapper.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                if (mappedLocs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    mappedLocs = new ArrayList<Location>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    lineMapper.put(key, mappedLocs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                mappedLocs.add(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        info = new SoftLocationXRefs(stratumID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                                lineMapper, lineLocations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                                lowestLine, highestLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        softOtherLocationXRefsRef = new SoftReference<SoftLocationXRefs>(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    private SoftLocationXRefs getBaseLocations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        SoftLocationXRefs info = (softBaseLocationXRefsRef == null) ? null :
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   351
                                     softBaseLocationXRefsRef.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (info != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        JDWP.Method.LineTable lntab = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            lntab = JDWP.Method.LineTable.process(vm, declaringType, ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
             * Note: the absent info error shouldn't happen here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
             * because the first and last index are always available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        int count  = lntab.lines.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        List<Location> lineLocations = new ArrayList<Location>(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        Map<Integer, List<Location>>lineMapper = new HashMap<Integer, List<Location>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        int lowestLine = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        int highestLine = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            long bci = lntab.lines[i].lineCodeIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            int lineNumber = lntab.lines[i].lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
             * Some compilers will point multiple consecutive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
             * lines at the same location. We need to choose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
             * one of them so that we can consistently map back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
             * and forth between line and location. So we choose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
             * to record only the last line entry at a particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
             * location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            if ((i + 1 == count) || (bci != lntab.lines[i+1].lineCodeIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                // Remember the largest/smallest line number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                if (lineNumber > highestLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    highestLine = lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                if ((lineNumber < lowestLine) || (lowestLine == -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    lowestLine = lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                LocationImpl loc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                    new LocationImpl(virtualMachine(), this, bci);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                loc.addBaseLineInfo(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                    new BaseLineInfo(lineNumber, declaringType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                // Add to the location list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                lineLocations.add(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                // Add to the line -> locations map
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 14342
diff changeset
   402
                Integer key = lineNumber;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                List<Location> mappedLocs = lineMapper.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                if (mappedLocs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                    mappedLocs = new ArrayList<Location>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    lineMapper.put(key, mappedLocs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                mappedLocs.add(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
         * firstIndex, lastIndex, and startLocation need to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
         * retrieved only once since they are strongly referenced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        if (location == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            firstIndex = lntab.start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            lastIndex = lntab.end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
             * The startLocation is the first one in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
             * location list if we have one;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
             * otherwise, we construct a location for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
             * method start with no line info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            if (count > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                location = lineLocations.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                location = new LocationImpl(virtualMachine(), this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                                            firstIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        info = new SoftLocationXRefs(SDE.BASE_STRATUM_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                                lineMapper, lineLocations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                                lowestLine, highestLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        softBaseLocationXRefsRef = new SoftReference<SoftLocationXRefs>(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    private List<LocalVariable> getVariables1_4() throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        JDWP.Method.VariableTable vartab = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            vartab = JDWP.Method.VariableTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                                     process(vm, declaringType, ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            if (exc.errorCode() == JDWP.Error.ABSENT_INFORMATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                absentVariableInformation = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                throw new AbsentInformationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        // Get the number of slots used by argument variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        argSlotCount = vartab.argCnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        int count = vartab.slots.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        List<LocalVariable> variables = new ArrayList<LocalVariable>(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        for (int i=0; i<count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            JDWP.Method.VariableTable.SlotInfo si = vartab.slots[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
             * Skip "this*" entries because they are never real
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
             * variables from the JLS perspective.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            if (!si.name.startsWith("this$") && !si.name.equals("this")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                Location scopeStart = new LocationImpl(virtualMachine(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                                                       this, si.codeIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                Location scopeEnd =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    new LocationImpl(virtualMachine(), this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                                     si.codeIndex + si.length - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                LocalVariable variable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    new LocalVariableImpl(virtualMachine(), this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                                          si.slot, scopeStart, scopeEnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                                          si.name, si.signature, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                // Add to the variable list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                variables.add(variable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        return variables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    private List<LocalVariable> getVariables1() throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        if (!vm.canGet1_5LanguageFeatures()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            return getVariables1_4();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        JDWP.Method.VariableTableWithGeneric vartab = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            vartab = JDWP.Method.VariableTableWithGeneric.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                                     process(vm, declaringType, ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            if (exc.errorCode() == JDWP.Error.ABSENT_INFORMATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                absentVariableInformation = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                throw new AbsentInformationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        // Get the number of slots used by argument variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        argSlotCount = vartab.argCnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        int count = vartab.slots.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        List<LocalVariable> variables = new ArrayList<LocalVariable>(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        for (int i=0; i<count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            JDWP.Method.VariableTableWithGeneric.SlotInfo si = vartab.slots[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
             * Skip "this*" entries because they are never real
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
             * variables from the JLS perspective.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            if (!si.name.startsWith("this$") && !si.name.equals("this")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                Location scopeStart = new LocationImpl(virtualMachine(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                                                       this, si.codeIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                Location scopeEnd =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                    new LocationImpl(virtualMachine(), this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                                     si.codeIndex + si.length - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                LocalVariable variable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                    new LocalVariableImpl(virtualMachine(), this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                                          si.slot, scopeStart, scopeEnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                                          si.name, si.signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                                          si.genericSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                // Add to the variable list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                variables.add(variable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        return variables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    private List<LocalVariable> getVariables() throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        if (absentVariableInformation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            throw new AbsentInformationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        List<LocalVariable> variables = (variablesRef == null) ? null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                                        variablesRef.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        if (variables != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            return variables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        variables = getVariables1();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        variables = Collections.unmodifiableList(variables);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        variablesRef = new SoftReference<List<LocalVariable>>(variables);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        return variables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
}