src/jdk.jdi/share/classes/com/sun/tools/jdi/ConcreteMethodImpl.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 45714 jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/ConcreteMethodImpl.java@1820d351198d
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
     2
 * Copyright (c) 2000, 2017, 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
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    28
import java.lang.ref.SoftReference;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    29
import java.util.ArrayList;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    30
import java.util.Collections;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    31
import java.util.HashMap;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    32
import java.util.Iterator;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Map;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    35
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    36
import com.sun.jdi.AbsentInformationException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    37
import com.sun.jdi.LocalVariable;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    38
import com.sun.jdi.Location;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    39
import com.sun.jdi.VirtualMachine;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    40
import com.sun.tools.jdi.JDWP.Method.VariableTable;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    41
import com.sun.tools.jdi.JDWP.Method.VariableTableWithGeneric;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Represents methods with method bodies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * That is, non-native non-abstract methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Private to MethodImpl.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class ConcreteMethodImpl extends MethodImpl {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * A subset of the line number info that is softly cached
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static private class SoftLocationXRefs {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    54
        final String stratumID;                        // The stratum of this information
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    55
        final Map<Integer, List<Location>> lineMapper; // Maps line number to location(s)
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    56
        final List<Location> lineLocations;            // List of locations ordered by code index
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
         * Note: these do not necessarily correspond to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
         * the line numbers of the first and last elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
         * in the lineLocations list. Use these only for bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
         * checking and with lineMapper.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
         */
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    64
        @SuppressWarnings("unused")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        final int lowestLine;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    66
        @SuppressWarnings("unused")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        final int highestLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    69
        SoftLocationXRefs(String stratumID, Map<Integer, List<Location>> lineMapper,
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    70
                          List<Location> lineLocations, int lowestLine, int highestLine) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            this.stratumID = stratumID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            this.lineMapper = Collections.unmodifiableMap(lineMapper);
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    73
            this.lineLocations = Collections.unmodifiableList(lineLocations);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            this.lowestLine = lowestLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            this.highestLine = highestLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private Location location = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private SoftReference<SoftLocationXRefs> softBaseLocationXRefsRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private SoftReference<SoftLocationXRefs> softOtherLocationXRefsRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private SoftReference<List<LocalVariable>> variablesRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private boolean absentVariableInformation = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private long firstIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private long lastIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private SoftReference<byte[]> bytecodesRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private int argSlotCount = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    ConcreteMethodImpl(VirtualMachine vm, ReferenceTypeImpl declaringType,
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    90
                       long ref, String name, String signature,
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    91
                       String genericSignature, int modifiers)
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    92
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        // The generic signature is set when this is created
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    94
        super(vm, declaringType, ref, name, signature, genericSignature, modifiers);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public Location location() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (location == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            getBaseLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    List<Location> sourceNameFilter(List<Location> list,
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   105
                                    SDE.Stratum stratum,
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   106
                                    String sourceName)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                            throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (sourceName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            return list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            /* needs sourceName filteration */
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   112
            List<Location> locs = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            for (Location loc : list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                if (((LocationImpl)loc).sourceName(stratum).equals(sourceName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    locs.add(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            return locs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    List<Location> allLineLocations(SDE.Stratum stratum,
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   123
                                    String sourceName)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                            throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        List<Location> lineLocations = getLocations(stratum).lineLocations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (lineLocations.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            throw new AbsentInformationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return Collections.unmodifiableList(
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   132
            sourceNameFilter(lineLocations, stratum, sourceName));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    List<Location> locationsOfLine(SDE.Stratum stratum,
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   136
                                   String sourceName,
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   137
                                   int lineNumber)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                            throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        SoftLocationXRefs info = getLocations(stratum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (info.lineLocations.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            throw new AbsentInformationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         * Find the locations which match the line number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         * passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         */
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 14342
diff changeset
   149
        List<Location> list = info.lineMapper.get(lineNumber);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (list == null) {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   152
            list = new ArrayList<>(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return Collections.unmodifiableList(
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   155
            sourceNameFilter(list, stratum, sourceName));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public Location locationOfCodeIndex(long codeIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (firstIndex == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            getBaseLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         * Check for invalid code index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if (codeIndex < firstIndex || codeIndex > lastIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return new LocationImpl(virtualMachine(), this, codeIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    LineInfo codeIndexToLineInfo(SDE.Stratum stratum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                 long codeIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (firstIndex == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            getBaseLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
         * Check for invalid code index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (codeIndex < firstIndex || codeIndex > lastIndex) {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   183
            throw new InternalError("Location with invalid code index");
2
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
    public List<LocalVariable> variables() throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return getVariables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public List<LocalVariable> variablesByName(String name) throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        List<LocalVariable> variables = getVariables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   222
        List<LocalVariable> retList = new ArrayList<>(2);
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   223
        Iterator<LocalVariable> iter = variables.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        while(iter.hasNext()) {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   225
            LocalVariable variable = iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            if (variable.name().equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                retList.add(variable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return retList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public List<LocalVariable> arguments() throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        List<LocalVariable> variables = getVariables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   236
        List<LocalVariable> retList = new ArrayList<>(variables.size());
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   237
        Iterator<LocalVariable> iter = variables.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        while(iter.hasNext()) {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   239
            LocalVariable variable = iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            if (variable.isArgument()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                retList.add(variable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return retList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public byte[] bytecodes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        byte[] bytecodes = (bytecodesRef == null) ? null :
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   249
                                     bytecodesRef.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if (bytecodes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                bytecodes = JDWP.Method.Bytecodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                                 process(vm, declaringType, ref).bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   257
            bytecodesRef = new SoftReference<>(bytecodes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
         * Arrays are always modifiable, so it is a little unsafe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
         * to return the cached bytecodes directly; instead, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
         * make a clone at the cost of using more memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
         */
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   264
        return bytecodes.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    int argSlotCount() throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        if (argSlotCount == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            getVariables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return argSlotCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    private SoftLocationXRefs getLocations(SDE.Stratum stratum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        if (stratum.isJava()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            return getBaseLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        String stratumID = stratum.id();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        SoftLocationXRefs info =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            (softOtherLocationXRefsRef == null) ? null :
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   281
               softOtherLocationXRefsRef.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (info != null && info.stratumID.equals(stratumID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        List<Location> lineLocations = new ArrayList<Location>();
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   287
        Map<Integer, List<Location>> lineMapper = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        int lowestLine = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        int highestLine = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        SDE.LineStratum lastLineStratum = null;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   291
        SDE.Stratum baseStratum = declaringType.stratum(SDE.BASE_STRATUM_NAME);
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   292
        Iterator<Location> it = getBaseLocations().lineLocations.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        while(it.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            LocationImpl loc = (LocationImpl)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            int baseLineNumber = loc.lineNumber(baseStratum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            SDE.LineStratum lineStratum =
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   297
                  stratum.lineStratum(declaringType, baseLineNumber);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            if (lineStratum == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                // location not mapped in this stratum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            int lineNumber = lineStratum.lineNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            // remove unmapped and dup lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            if ((lineNumber != -1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                          (!lineStratum.equals(lastLineStratum))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                lastLineStratum = lineStratum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                // Remember the largest/smallest line number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                if (lineNumber > highestLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    highestLine = lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                if ((lineNumber < lowestLine) || (lowestLine == -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    lowestLine = lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                loc.addStratumLineInfo(
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   320
                    new StratumLineInfo(stratumID,
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   321
                                        lineNumber,
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   322
                                        lineStratum.sourceName(),
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   323
                                        lineStratum.sourcePath()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                // Add to the location list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                lineLocations.add(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                // 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
   329
                Integer key = lineNumber;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                List<Location> mappedLocs = lineMapper.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                if (mappedLocs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                    mappedLocs = new ArrayList<Location>(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    lineMapper.put(key, mappedLocs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                mappedLocs.add(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   339
        info = new SoftLocationXRefs(stratumID, lineMapper, lineLocations,
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   340
                                     lowestLine, highestLine);
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   341
        softOtherLocationXRefsRef = new SoftReference<>(info);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    private SoftLocationXRefs getBaseLocations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        SoftLocationXRefs info = (softBaseLocationXRefsRef == null) ? null :
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   347
                                     softBaseLocationXRefsRef.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (info != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        JDWP.Method.LineTable lntab = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            lntab = JDWP.Method.LineTable.process(vm, declaringType, ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
             * Note: the absent info error shouldn't happen here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
             * because the first and last index are always available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        int count  = lntab.lines.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   365
        List<Location> lineLocations = new ArrayList<>(count);
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   366
        Map<Integer, List<Location>>lineMapper = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        int lowestLine = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        int highestLine = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            long bci = lntab.lines[i].lineCodeIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            int lineNumber = lntab.lines[i].lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
             * Some compilers will point multiple consecutive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
             * lines at the same location. We need to choose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
             * one of them so that we can consistently map back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
             * and forth between line and location. So we choose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
             * to record only the last line entry at a particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
             * location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            if ((i + 1 == count) || (bci != lntab.lines[i+1].lineCodeIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                // Remember the largest/smallest line number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                if (lineNumber > highestLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    highestLine = lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                if ((lineNumber < lowestLine) || (lowestLine == -1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    lowestLine = lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                LocationImpl loc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                    new LocationImpl(virtualMachine(), this, bci);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                loc.addBaseLineInfo(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    new BaseLineInfo(lineNumber, declaringType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                // Add to the location list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                lineLocations.add(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                // 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
   398
                Integer key = lineNumber;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                List<Location> mappedLocs = lineMapper.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                if (mappedLocs == null) {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   401
                    mappedLocs = new ArrayList<>(1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    lineMapper.put(key, mappedLocs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                mappedLocs.add(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
         * firstIndex, lastIndex, and startLocation need to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
         * retrieved only once since they are strongly referenced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        if (location == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            firstIndex = lntab.start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            lastIndex = lntab.end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
             * The startLocation is the first one in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
             * location list if we have one;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
             * otherwise, we construct a location for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
             * method start with no line info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            if (count > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                location = lineLocations.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                location = new LocationImpl(virtualMachine(), this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                            firstIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        info = new SoftLocationXRefs(SDE.BASE_STRATUM_NAME,
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   430
                                     lineMapper, lineLocations,
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   431
                                     lowestLine, highestLine);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        softBaseLocationXRefsRef = new SoftReference<SoftLocationXRefs>(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    private List<LocalVariable> getVariables1_4() throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        JDWP.Method.VariableTable vartab = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            vartab = JDWP.Method.VariableTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                                     process(vm, declaringType, ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            if (exc.errorCode() == JDWP.Error.ABSENT_INFORMATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                absentVariableInformation = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                throw new AbsentInformationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        // Get the number of slots used by argument variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        argSlotCount = vartab.argCnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        int count = vartab.slots.length;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   453
        List<LocalVariable> variables = new ArrayList<>(count);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        for (int i=0; i<count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            JDWP.Method.VariableTable.SlotInfo si = vartab.slots[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
             * Skip "this*" entries because they are never real
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
             * variables from the JLS perspective.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            if (!si.name.startsWith("this$") && !si.name.equals("this")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                Location scopeStart = new LocationImpl(virtualMachine(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                                                       this, si.codeIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                Location scopeEnd =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                    new LocationImpl(virtualMachine(), this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                     si.codeIndex + si.length - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                LocalVariable variable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    new LocalVariableImpl(virtualMachine(), this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                          si.slot, scopeStart, scopeEnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                                          si.name, si.signature, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                // Add to the variable list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                variables.add(variable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        return variables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    private List<LocalVariable> getVariables1() throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if (!vm.canGet1_5LanguageFeatures()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            return getVariables1_4();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        JDWP.Method.VariableTableWithGeneric vartab = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            vartab = JDWP.Method.VariableTableWithGeneric.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                                     process(vm, declaringType, ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            if (exc.errorCode() == JDWP.Error.ABSENT_INFORMATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                absentVariableInformation = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                throw new AbsentInformationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        // Get the number of slots used by argument variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        argSlotCount = vartab.argCnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        int count = vartab.slots.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        List<LocalVariable> variables = new ArrayList<LocalVariable>(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        for (int i=0; i<count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            JDWP.Method.VariableTableWithGeneric.SlotInfo si = vartab.slots[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
             * Skip "this*" entries because they are never real
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
             * variables from the JLS perspective.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            if (!si.name.startsWith("this$") && !si.name.equals("this")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                Location scopeStart = new LocationImpl(virtualMachine(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                                                       this, si.codeIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                Location scopeEnd =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                    new LocationImpl(virtualMachine(), this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                                     si.codeIndex + si.length - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                LocalVariable variable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                    new LocalVariableImpl(virtualMachine(), this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                                          si.slot, scopeStart, scopeEnd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                                          si.name, si.signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                                          si.genericSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                // Add to the variable list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                variables.add(variable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        return variables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    private List<LocalVariable> getVariables() throws AbsentInformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        if (absentVariableInformation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            throw new AbsentInformationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        List<LocalVariable> variables = (variablesRef == null) ? null :
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   532
                                         variablesRef.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        if (variables != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            return variables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        variables = getVariables1();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        variables = Collections.unmodifiableList(variables);
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   538
        variablesRef = new SoftReference<>(variables);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        return variables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
}