src/jdk.jdi/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java
author dholmes
Sat, 23 Jun 2018 01:32:41 -0400
changeset 50735 2f2af62dfac7
parent 47216 71c04702a3d5
child 54270 176e8aec3097
permissions -rw-r--r--
8010319: Implementation of JEP 181: Nest-Based Access Control Reviewed-by: alanb, psandoz, mchung, coleenp, acorn, mcimadamore, forax, jlahoda, sspitsyn, abuckley Contributed-by: alex.buckley@oracle.com, maurizio.mimadamore@oracle.com, mandy.chung@oracle.com, tobias.hartmann@oracle.com, david.holmes@oracle.com, vladimir.x.ivanov@oracle.com, karen.kinnear@oracle.com, vladimir.kozlov@oracle.com, john.r.rose@oracle.com, daniel.smith@oracle.com, serguei.spitsyn@oracle.com, kumardotsrinivasan@gmail.com, boris.ulasevich@bell-sw.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
     2
 * Copyright (c) 1998, 2018, 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: 839
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: 839
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: 839
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 839
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 839
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: 38332
diff changeset
    28
import java.lang.ref.Reference;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    29
import java.lang.ref.ReferenceQueue;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    30
import java.lang.ref.SoftReference;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    31
import java.text.MessageFormat;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    32
import java.util.ArrayList;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    33
import java.util.Arrays;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    34
import java.util.Collections;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    35
import java.util.HashMap;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    36
import java.util.Iterator;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    37
import java.util.List;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    38
import java.util.Map;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    39
import java.util.TreeSet;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    40
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    41
import com.sun.jdi.BooleanType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    42
import com.sun.jdi.BooleanValue;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    43
import com.sun.jdi.ByteType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    44
import com.sun.jdi.ByteValue;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    45
import com.sun.jdi.CharType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    46
import com.sun.jdi.CharValue;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    47
import com.sun.jdi.ClassLoaderReference;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    48
import com.sun.jdi.ClassNotLoadedException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    49
import com.sun.jdi.DoubleType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    50
import com.sun.jdi.DoubleValue;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    51
import com.sun.jdi.FloatType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    52
import com.sun.jdi.FloatValue;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    53
import com.sun.jdi.IntegerType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    54
import com.sun.jdi.IntegerValue;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    55
import com.sun.jdi.InternalException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    56
import com.sun.jdi.LongType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    57
import com.sun.jdi.LongValue;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
    58
import com.sun.jdi.ModuleReference;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    59
import com.sun.jdi.PathSearchingVirtualMachine;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    60
import com.sun.jdi.PrimitiveType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    61
import com.sun.jdi.ReferenceType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    62
import com.sun.jdi.ShortType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    63
import com.sun.jdi.ShortValue;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    64
import com.sun.jdi.StringReference;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    65
import com.sun.jdi.ThreadGroupReference;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    66
import com.sun.jdi.ThreadReference;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    67
import com.sun.jdi.Type;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    68
import com.sun.jdi.VMDisconnectedException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    69
import com.sun.jdi.VirtualMachine;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    70
import com.sun.jdi.VirtualMachineManager;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    71
import com.sun.jdi.VoidType;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    72
import com.sun.jdi.VoidValue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
import com.sun.jdi.connect.spi.Connection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
import com.sun.jdi.event.EventQueue;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    75
import com.sun.jdi.request.BreakpointRequest;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    76
import com.sun.jdi.request.EventRequest;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
    77
import com.sun.jdi.request.EventRequestManager;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
class VirtualMachineImpl extends MirrorImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
             implements PathSearchingVirtualMachine, ThreadListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    // VM Level exported variables, these
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // are unique to a given vm
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public final int sizeofFieldRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public final int sizeofMethodRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public final int sizeofObjectRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public final int sizeofClassRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public final int sizeofFrameRef;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
    88
    public final int sizeofModuleRef;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    final int sequenceNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private final TargetVM target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private final EventQueueImpl eventQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private final EventRequestManagerImpl internalEventRequestManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private final EventRequestManagerImpl eventRequestManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    final VirtualMachineManagerImpl vmManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private final ThreadGroup threadGroupForJDI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    // Allow direct access to this field so that that tracing code slows down
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    // JDI as little as possible when not enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    int traceFlags = TRACE_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    static int TRACE_RAW_SENDS     = 0x01000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    static int TRACE_RAW_RECEIVES  = 0x02000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    boolean traceReceives = false;   // pre-compute because of frequency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    // ReferenceType access - updated with class prepare and unload events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    // Protected by "synchronized(this)". "retrievedAllTypes" may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    // tested unsynchronized (since once true, it stays true), but must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    // be set synchronously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private Map<Long, ReferenceType> typesByID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private TreeSet<ReferenceType> typesBySignature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private boolean retrievedAllTypes = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   116
    private Map<Long, ModuleReference> modulesByID;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   117
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    // For other languages support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private String defaultStratum = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    // ObjectReference cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    // "objectsByID" protected by "synchronized(this)".
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   123
    private final Map<Long, SoftObjectReference> objectsByID = new HashMap<>();
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   124
    private final ReferenceQueue<ObjectReferenceImpl> referenceQueue = new ReferenceQueue<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    static private final int DISPOSE_THRESHOLD = 50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private final List<SoftObjectReference> batchedDisposeRequests =
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   127
            Collections.synchronizedList(new ArrayList<>(DISPOSE_THRESHOLD + 10));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    // These are cached once for the life of the VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private JDWP.VirtualMachine.Version versionInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private JDWP.VirtualMachine.ClassPaths pathInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private JDWP.VirtualMachine.Capabilities capabilities = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private JDWP.VirtualMachine.CapabilitiesNew capabilitiesNew = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    // Per-vm singletons for primitive types and for void.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    // singleton-ness protected by "synchronized(this)".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private BooleanType theBooleanType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private ByteType    theByteType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private CharType    theCharType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private ShortType   theShortType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private IntegerType theIntegerType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private LongType    theLongType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private FloatType   theFloatType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private DoubleType  theDoubleType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    private VoidType    theVoidType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private VoidValue voidVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    // Launched debuggee process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private Process process;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    // coordinates state changes and corresponding listener notifications
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    private VMState state = new VMState(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    private Object initMonitor = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    private boolean initComplete = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    private boolean shutdown = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private void notifyInitCompletion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        synchronized(initMonitor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            initComplete = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            initMonitor.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    void waitInitCompletion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        synchronized(initMonitor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            while (!initComplete) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    initMonitor.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            }
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
    VMState state() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * ThreadListener implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public boolean threadResumable(ThreadAction action) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
         * If any thread is resumed, the VM is considered not suspended.
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 51
diff changeset
   189
         * Just one thread is being resumed so pass it to thaw.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
         */
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 51
diff changeset
   191
        state.thaw(action.thread());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    VirtualMachineImpl(VirtualMachineManager manager,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                       Connection connection, Process process,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                       int sequenceNumber) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        super(null);  // Can't use super(this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        vm = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        this.vmManager = (VirtualMachineManagerImpl)manager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        this.process = process;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        this.sequenceNumber = sequenceNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        /* Create ThreadGroup to be used by all threads servicing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
         * this VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        threadGroupForJDI = new ThreadGroup(vmManager.mainGroupForJDI(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                            "JDI [" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                            this.hashCode() + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
         * Set up a thread to communicate with the target VM over
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         * the specified transport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        target = new TargetVM(this, connection);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
         * Set up a thread to handle events processed internally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
         * the JDI implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        EventQueueImpl internalEventQueue = new EventQueueImpl(this, target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        new InternalEventHandler(this, internalEventQueue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
         * Initialize client access to event setting and handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        eventQueue = new EventQueueImpl(this, target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        eventRequestManager = new EventRequestManagerImpl(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        target.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
         * Many ids are variably sized, depending on target VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
         * Find out the sizes right away.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        JDWP.VirtualMachine.IDSizes idSizes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            idSizes = JDWP.VirtualMachine.IDSizes.process(vm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        sizeofFieldRef  = idSizes.fieldIDSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        sizeofMethodRef = idSizes.methodIDSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        sizeofObjectRef = idSizes.objectIDSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        sizeofClassRef = idSizes.referenceTypeIDSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        sizeofFrameRef  = idSizes.frameIDSize;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   247
        sizeofModuleRef = idSizes.objectIDSize;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
         * Set up requests needed by internal event handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
         * Make sure they are distinguished by creating them with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
         * an internal event request manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
         * Warning: create events only with SUSPEND_NONE policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
         * In the current implementation other policies will not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
         * be handled correctly when the event comes in. (notfiySuspend()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
         * will not be properly called, and if the event is combined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
         * with external events in the same set, suspend policy is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
         * correctly determined for the internal vs. external event sets)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        internalEventRequestManager = new EventRequestManagerImpl(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        EventRequest er = internalEventRequestManager.createClassPrepareRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        er.setSuspendPolicy(EventRequest.SUSPEND_NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        er.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        er = internalEventRequestManager.createClassUnloadRequest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        er.setSuspendPolicy(EventRequest.SUSPEND_NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        er.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
         * Tell other threads, notably TargetVM, that initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
         * is complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        notifyInitCompletion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    EventRequestManagerImpl getInternalEventRequestManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        return internalEventRequestManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    void validateVM() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
         * We no longer need to do this.  The spec now says
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
         * that a VMDisconnected _may_ be thrown in these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
         * cases, not that it _will_ be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
         * So, to simplify things we will just let the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
         * caller's of this method proceed with their business.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
         * If the debuggee is disconnected, either because it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
         * crashed or finished or something, or because the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
         * debugger called exit() or dispose(), then if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
         * we end up trying to communicate with the debuggee,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
         * code in TargetVM will throw a VMDisconnectedException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
         * This means that if we can satisfy a request without
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
         * talking to the debuggee, (eg, with cached data) then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
         * VMDisconnectedException will _not_ be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
         * if (shutdown) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
         *    throw new VMDisconnectedException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
         * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return this == obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        return System.identityHashCode(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   309
    public List<ModuleReference> allModules() {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   310
        validateVM();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   311
        List<ModuleReference> modules = retrieveAllModules();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   312
        return Collections.unmodifiableList(modules);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   313
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   314
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public List<ReferenceType> classesByName(String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        String signature = JNITypeParser.typeNameToSignature(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        List<ReferenceType> list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        if (retrievedAllTypes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
           list = findReferenceTypes(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
           list = retrieveClassesBySignature(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        return Collections.unmodifiableList(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    public List<ReferenceType> allClasses() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if (!retrievedAllTypes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            retrieveAllClasses();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        ArrayList<ReferenceType> a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        synchronized (this) {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   335
            a = new ArrayList<>(typesBySignature);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        return Collections.unmodifiableList(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    public void
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   341
        redefineClasses(Map<? extends ReferenceType, byte[]> classToBytes)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        int cnt = classToBytes.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        JDWP.VirtualMachine.RedefineClasses.ClassDef[] defs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            new JDWP.VirtualMachine.RedefineClasses.ClassDef[cnt];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        if (!canRedefineClasses()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   350
        Iterator<?> it = classToBytes.entrySet().iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        for (int i = 0; it.hasNext(); i++) {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   352
            @SuppressWarnings("rawtypes")
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   353
            Map.Entry<?, ?> entry = (Map.Entry)it.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            ReferenceTypeImpl refType = (ReferenceTypeImpl)entry.getKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            validateMirror(refType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            defs[i] = new JDWP.VirtualMachine.RedefineClasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                       .ClassDef(refType, (byte[])entry.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        // flush caches and disable caching until the next suspend
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        vm.state().thaw();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            JDWP.VirtualMachine.RedefineClasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                process(vm, defs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            switch (exc.errorCode()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            case JDWP.Error.INVALID_CLASS_FORMAT :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                throw new ClassFormatError(
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   370
                    "class not in class file format");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            case JDWP.Error.CIRCULAR_CLASS_DEFINITION :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                throw new ClassCircularityError(
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   373
                    "circularity has been detected while initializing a class");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            case JDWP.Error.FAILS_VERIFICATION :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                throw new VerifyError(
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   376
                    "verifier detected internal inconsistency or security problem");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            case JDWP.Error.UNSUPPORTED_VERSION :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                throw new UnsupportedClassVersionError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    "version numbers of class are not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            case JDWP.Error.ADD_METHOD_NOT_IMPLEMENTED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                throw new UnsupportedOperationException(
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   382
                    "add method not implemented");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            case JDWP.Error.SCHEMA_CHANGE_NOT_IMPLEMENTED :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                throw new UnsupportedOperationException(
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   385
                    "schema change not implemented");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            case JDWP.Error.HIERARCHY_CHANGE_NOT_IMPLEMENTED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                throw new UnsupportedOperationException(
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   388
                    "hierarchy change not implemented");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            case JDWP.Error.DELETE_METHOD_NOT_IMPLEMENTED :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                throw new UnsupportedOperationException(
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   391
                    "delete method not implemented");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            case JDWP.Error.CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                throw new UnsupportedOperationException(
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   394
                    "changes to class modifiers not implemented");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            case JDWP.Error.METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                throw new UnsupportedOperationException(
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   397
                    "changes to method modifiers not implemented");
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
   398
            case JDWP.Error.CLASS_ATTRIBUTE_CHANGE_NOT_IMPLEMENTED :
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
   399
                throw new UnsupportedOperationException(
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
   400
                    "changes to class attribute not implemented");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            case JDWP.Error.NAMES_DONT_MATCH :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                throw new NoClassDefFoundError(
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   403
                    "class names do not match");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                throw exc.toJDIException();
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
        // Delete any record of the breakpoints
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   410
        List<BreakpointRequest> toDelete = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        EventRequestManager erm = eventRequestManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        it = erm.breakpointRequests().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        while (it.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            BreakpointRequest req = (BreakpointRequest)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            if (classToBytes.containsKey(req.location().declaringType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                toDelete.add(req);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        erm.deleteEventRequests(toDelete);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        // Invalidate any information cached for the classes just redefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        it = classToBytes.keySet().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        while (it.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            ReferenceTypeImpl rti = (ReferenceTypeImpl)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            rti.noticeRedefineClass();
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
    public List<ThreadReference> allThreads() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        return state.allThreads();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    public List<ThreadGroupReference> topLevelThreadGroups() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        return state.topLevelThreadGroups();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * Sends a command to the back end which is defined to do an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * implicit vm-wide resume. The VM can no longer be considered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * suspended, so certain cached data must be invalidated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    PacketStream sendResumingCommand(CommandSender sender) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        return state.thawCommand(sender);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * The VM has been suspended. Additional caching can be done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * as long as there are no pending resumes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    void notifySuspend() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        state.freeze();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    public void suspend() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            JDWP.VirtualMachine.Suspend.process(vm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        notifySuspend();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    public void resume() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        CommandSender sender =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            new CommandSender() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                public PacketStream send() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    return JDWP.VirtualMachine.Resume.enqueueCommand(vm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            PacketStream stream = state.thawCommand(sender);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            JDWP.VirtualMachine.Resume.waitForReply(vm, stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        } catch (VMDisconnectedException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
             * If the debugger makes a VMDeathRequest with SUSPEND_ALL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
             * then when it does an EventSet.resume after getting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
             * VMDeathEvent, the normal flow of events is that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
             * BE shuts down, but the waitForReply comes back ok.  In this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
             * case, the run loop in TargetVM that is waiting for a packet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
             * gets an EOF because the socket closes. It generates a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
             * VMDisconnectedEvent and everyone is happy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
             * However, sometimes, the BE gets shutdown before this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
             * waitForReply completes.  In this case, TargetVM.waitForReply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
             * gets awakened with no reply and so gens a VMDisconnectedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
             * which is not what we want.  It might be possible to fix this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
             * in the BE, but it is ok to just ignore the VMDisconnectedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
             * here.  This will allow the VMDisconnectedEvent to be generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
             * correctly.  And, if the debugger should happen to make another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
             * request, it will get a VMDisconnectedException at that time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            switch (exc.errorCode()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                case JDWP.Error.VM_DEAD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                    throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    public EventQueue eventQueue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
         * No VM validation here. We allow access to the event queue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
         * after disconnection, so that there is access to the terminating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
         * events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        return eventQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    public EventRequestManager eventRequestManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        return eventRequestManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    EventRequestManagerImpl eventRequestManagerImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        return eventRequestManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    public BooleanValue mirrorOf(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        return new BooleanValueImpl(this,value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    public ByteValue mirrorOf(byte value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        return new ByteValueImpl(this,value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    public CharValue mirrorOf(char value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        return new CharValueImpl(this,value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public ShortValue mirrorOf(short value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        return new ShortValueImpl(this,value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    public IntegerValue mirrorOf(int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        return new IntegerValueImpl(this,value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    public LongValue mirrorOf(long value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        return new LongValueImpl(this,value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    public FloatValue mirrorOf(float value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        return new FloatValueImpl(this,value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    public DoubleValue mirrorOf(double value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        return new DoubleValueImpl(this,value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    public StringReference mirrorOf(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        try {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   566
            return JDWP.VirtualMachine.CreateString.
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   567
                process(vm, value).stringObject;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    public VoidValue mirrorOfVoid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        if (voidVal == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            voidVal = new VoidValueImpl(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        return voidVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    public long[] instanceCounts(List<? extends ReferenceType> classes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        if (!canGetInstanceInfo()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            throw new UnsupportedOperationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                "target does not support getting instances");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        long[] retValue ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        ReferenceTypeImpl[] rtArray = new ReferenceTypeImpl[classes.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        int ii = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        for (ReferenceType rti: classes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            validateMirror(rti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            rtArray[ii++] = (ReferenceTypeImpl)rti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            retValue = JDWP.VirtualMachine.InstanceCounts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                                process(vm, rtArray).counts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        shutdown = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            JDWP.VirtualMachine.Dispose.process(vm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        target.stopListening();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    public void exit(int exitCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        shutdown = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            JDWP.VirtualMachine.Exit.process(vm, exitCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        target.stopListening();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    public Process process() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        return process;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    private JDWP.VirtualMachine.Version versionInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
       try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
           if (versionInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
               // Need not be synchronized since it is static information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
               versionInfo = JDWP.VirtualMachine.Version.process(vm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
           return versionInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
       } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
           throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
       }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   639
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   640
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    public String description() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        return MessageFormat.format(vmManager.getString("version_format"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                                    "" + vmManager.majorInterfaceVersion(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                                    "" + vmManager.minorInterfaceVersion(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                                     versionInfo().description);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    public String version() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        return versionInfo().vmVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    public String name() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        return versionInfo().vmName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    public boolean canWatchFieldModification() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        return capabilities().canWatchFieldModification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   664
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    public boolean canWatchFieldAccess() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        return capabilities().canWatchFieldAccess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   669
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    public boolean canGetBytecodes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        return capabilities().canGetBytecodes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   674
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    public boolean canGetSyntheticAttribute() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        return capabilities().canGetSyntheticAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   679
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    public boolean canGetOwnedMonitorInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        return capabilities().canGetOwnedMonitorInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   684
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    public boolean canGetCurrentContendedMonitor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        return capabilities().canGetCurrentContendedMonitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   689
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    public boolean canGetMonitorInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        return capabilities().canGetMonitorInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    private boolean hasNewCapabilities() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        return versionInfo().jdwpMajor > 1 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            versionInfo().jdwpMinor >= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    boolean canGet1_5LanguageFeatures() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        return versionInfo().jdwpMajor > 1 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            versionInfo().jdwpMinor >= 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    public boolean canUseInstanceFilters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        return hasNewCapabilities() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            capabilitiesNew().canUseInstanceFilters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   710
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    public boolean canRedefineClasses() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        return hasNewCapabilities() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            capabilitiesNew().canRedefineClasses;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   716
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    public boolean canAddMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        return hasNewCapabilities() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            capabilitiesNew().canAddMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   722
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    public boolean canUnrestrictedlyRedefineClasses() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        return hasNewCapabilities() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            capabilitiesNew().canUnrestrictedlyRedefineClasses;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   728
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    public boolean canPopFrames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        return hasNewCapabilities() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            capabilitiesNew().canPopFrames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   734
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    public boolean canGetMethodReturnValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        return versionInfo().jdwpMajor > 1 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            versionInfo().jdwpMinor >= 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   739
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    public boolean canGetInstanceInfo() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   741
        if (versionInfo().jdwpMajor > 1 ||
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   742
            versionInfo().jdwpMinor >= 6) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   743
            validateVM();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   744
            return hasNewCapabilities() &&
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   745
                capabilitiesNew().canGetInstanceInfo;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   746
        } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   750
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    public boolean canUseSourceNameFilters() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   752
        return versionInfo().jdwpMajor > 1 ||
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   753
            versionInfo().jdwpMinor >= 6;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   755
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    public boolean canForceEarlyReturn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        return hasNewCapabilities() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            capabilitiesNew().canForceEarlyReturn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   761
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    public boolean canBeModified() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   765
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    public boolean canGetSourceDebugExtension() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        return hasNewCapabilities() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            capabilitiesNew().canGetSourceDebugExtension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   771
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    public boolean canGetClassFileVersion() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   773
        return versionInfo().jdwpMajor > 1 ||
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   774
            versionInfo().jdwpMinor >= 6;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   776
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    public boolean canGetConstantPool() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        return hasNewCapabilities() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            capabilitiesNew().canGetConstantPool;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   782
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    public boolean canRequestVMDeathEvent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        return hasNewCapabilities() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            capabilitiesNew().canRequestVMDeathEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   788
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    public boolean canRequestMonitorEvents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        return hasNewCapabilities() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            capabilitiesNew().canRequestMonitorEvents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   794
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    public boolean canGetMonitorFrameInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        return hasNewCapabilities() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            capabilitiesNew().canGetMonitorFrameInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   800
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   801
    public boolean canGetModuleInfo() {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   802
        validateVM();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   803
        return versionInfo().jdwpMajor >= 9;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
   804
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    public void setDebugTraceMode(int traceFlags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        validateVM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        this.traceFlags = traceFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        this.traceReceives = (traceFlags & TRACE_RECEIVES) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    void printTrace(String string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        System.err.println("[JDI: " + string + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    void printReceiveTrace(int depth, String string) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 14342
diff changeset
   817
        StringBuilder sb = new StringBuilder("Receiving:");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        for (int i = depth; i > 0; --i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            sb.append("    ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        sb.append(string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        printTrace(sb.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    private synchronized ReferenceTypeImpl addReferenceType(long id,
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   826
                                                            int tag,
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   827
                                                            String signature) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        if (typesByID == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            initReferenceTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        ReferenceTypeImpl type = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        switch(tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            case JDWP.TypeTag.CLASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                type = new ClassTypeImpl(vm, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            case JDWP.TypeTag.INTERFACE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                type = new InterfaceTypeImpl(vm, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            case JDWP.TypeTag.ARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                type = new ArrayTypeImpl(vm, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                throw new InternalException("Invalid reference type tag");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
         * If a signature was specified, make sure to set it ASAP, to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
         * prevent any needless JDWP command to retrieve it. (for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
         * typesBySignature.add needs the signature, to maintain proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
         * ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        if (signature != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            type.setSignature(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
25186
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 24969
diff changeset
   856
        typesByID.put(id, type);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        typesBySignature.add(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
           vm.printTrace("Caching new ReferenceType, sig=" + signature +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                         ", id=" + id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    synchronized void removeReferenceType(String signature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        if (typesByID == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
         * There can be multiple classes with the same name. Since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
         * we can't differentiate here, we first remove all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
         * matching classes from our cache...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
         */
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   876
        Iterator<ReferenceType> iter = typesBySignature.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        int matches = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            ReferenceTypeImpl type = (ReferenceTypeImpl)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            int comp = signature.compareTo(type.signature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            if (comp == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                matches++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                iter.remove();
25186
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 24969
diff changeset
   884
                typesByID.remove(type.ref());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                   vm.printTrace("Uncaching ReferenceType, sig=" + signature +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                                 ", id=" + type.ref());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                }
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   889
                // fix for 4359077, don't break out. list is no longer sorted
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   890
                // in the order we think
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
         * ...and if there was more than one, re-retrieve the classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
         * with that name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        if (matches > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            retrieveClassesBySignature(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    private synchronized List<ReferenceType> findReferenceTypes(String signature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        if (typesByID == null) {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   905
            return new ArrayList<>(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        }
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   907
        Iterator<ReferenceType> iter = typesBySignature.iterator();
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   908
        List<ReferenceType> list = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            ReferenceTypeImpl type = (ReferenceTypeImpl)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            int comp = signature.compareTo(type.signature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            if (comp == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                list.add(type);
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   914
                // fix for 4359077, don't break out. list is no longer sorted
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   915
                // in the order we think
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        return list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    private void initReferenceTypes() {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   922
        typesByID = new HashMap<>(300);
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   923
        typesBySignature = new TreeSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    ReferenceTypeImpl referenceType(long ref, byte tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        return referenceType(ref, tag, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    ClassTypeImpl classType(long ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        return (ClassTypeImpl)referenceType(ref, JDWP.TypeTag.CLASS, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    InterfaceTypeImpl interfaceType(long ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        return (InterfaceTypeImpl)referenceType(ref, JDWP.TypeTag.INTERFACE, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    ArrayTypeImpl arrayType(long ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        return (ArrayTypeImpl)referenceType(ref, JDWP.TypeTag.ARRAY, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
   942
    ReferenceTypeImpl referenceType(long id, int tag, String signature) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 14342
diff changeset
   944
            StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            sb.append("Looking up ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            if (tag == JDWP.TypeTag.CLASS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                sb.append("Class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            } else if (tag == JDWP.TypeTag.INTERFACE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                sb.append("Interface");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            } else if (tag == JDWP.TypeTag.ARRAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                sb.append("ArrayType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            } else {
27957
24b4e6082f19 8055723: Replace concat String to append in StringBuilder parameters (dev)
weijun
parents: 25859
diff changeset
   953
                sb.append("UNKNOWN TAG: ").append(tag);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            if (signature != null) {
27957
24b4e6082f19 8055723: Replace concat String to append in StringBuilder parameters (dev)
weijun
parents: 25859
diff changeset
   956
                sb.append(", signature='").append(signature).append('\'');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            }
27957
24b4e6082f19 8055723: Replace concat String to append in StringBuilder parameters (dev)
weijun
parents: 25859
diff changeset
   958
            sb.append(", id=").append(id);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            vm.printTrace(sb.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        if (id == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            ReferenceTypeImpl retType = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                if (typesByID != null) {
25186
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 24969
diff changeset
   967
                    retType = (ReferenceTypeImpl)typesByID.get(id);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                if (retType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                    retType = addReferenceType(id, tag, signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            return retType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    private JDWP.VirtualMachine.Capabilities capabilities() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        if (capabilities == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                capabilities = JDWP.VirtualMachine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                                 .Capabilities.process(vm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        return capabilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    private JDWP.VirtualMachine.CapabilitiesNew capabilitiesNew() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        if (capabilitiesNew == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                capabilitiesNew = JDWP.VirtualMachine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                                 .CapabilitiesNew.process(vm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        return capabilitiesNew;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1001
    private synchronized ModuleReference addModule(long id) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1002
        if (modulesByID == null) {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
  1003
            modulesByID = new HashMap<>(77);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1004
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1005
        ModuleReference module = new ModuleReferenceImpl(vm, id);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1006
        modulesByID.put(id, module);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1007
        return module;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1008
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1009
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1010
    ModuleReference getModule(long id) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1011
        if (id == 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1012
            return null;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1013
        } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1014
            ModuleReference module = null;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1015
            synchronized (this) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1016
                if (modulesByID != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1017
                    module = modulesByID.get(id);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1018
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1019
                if (module == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1020
                    module = addModule(id);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1021
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1022
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1023
            return module;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1024
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1025
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1026
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1027
    private synchronized List<ModuleReference> retrieveAllModules() {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1028
        ModuleReferenceImpl[] reqModules;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1029
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1030
            reqModules = JDWP.VirtualMachine.AllModules.process(vm).modules;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1031
        } catch (JDWPException exc) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1032
            throw exc.toJDIException();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1033
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1034
        ArrayList<ModuleReference> modules = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1035
        for (int i = 0; i < reqModules.length; i++) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1036
            long moduleRef = reqModules[i].ref();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1037
            ModuleReference module = getModule(moduleRef);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1038
            modules.add(module);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1039
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1040
        return modules;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1041
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1042
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    private List<ReferenceType> retrieveClassesBySignature(String signature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            vm.printTrace("Retrieving matching ReferenceTypes, sig=" + signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        JDWP.VirtualMachine.ClassesBySignature.ClassInfo[] cinfos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            cinfos = JDWP.VirtualMachine.ClassesBySignature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                                      process(vm, signature).classes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        int count = cinfos.length;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
  1056
        List<ReferenceType> list = new ArrayList<>(count);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        // Hold lock during processing to improve performance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                JDWP.VirtualMachine.ClassesBySignature.ClassInfo ci =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                                                               cinfos[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                ReferenceTypeImpl type = referenceType(ci.typeID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                                                       ci.refTypeTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                                                       signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                type.setStatus(ci.status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                list.add(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        return list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    private void retrieveAllClasses1_4() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        JDWP.VirtualMachine.AllClasses.ClassInfo[] cinfos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            cinfos = JDWP.VirtualMachine.AllClasses.process(vm).classes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        // Hold lock during processing to improve performance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        // and to have safe check/set of retrievedAllTypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            if (!retrievedAllTypes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                // Number of classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                int count = cinfos.length;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
  1087
                for (int i = 0; i < count; i++) {
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
  1088
                    JDWP.VirtualMachine.AllClasses.ClassInfo ci = cinfos[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                    ReferenceTypeImpl type = referenceType(ci.typeID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                                                           ci.refTypeTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                                                           ci.signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                    type.setStatus(ci.status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                retrievedAllTypes = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    private void retrieveAllClasses() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            vm.printTrace("Retrieving all ReferenceTypes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        if (!vm.canGet1_5LanguageFeatures()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            retrieveAllClasses1_4();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
         * To save time (assuming the caller will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
         * using then) we will get the generic sigs too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        JDWP.VirtualMachine.AllClassesWithGeneric.ClassInfo[] cinfos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            cinfos = JDWP.VirtualMachine.AllClassesWithGeneric.process(vm).classes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        // Hold lock during processing to improve performance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        // and to have safe check/set of retrievedAllTypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            if (!retrievedAllTypes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                // Number of classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                int count = cinfos.length;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 38332
diff changeset
  1126
                for (int i = 0; i < count; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                    JDWP.VirtualMachine.AllClassesWithGeneric.ClassInfo ci =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                                                               cinfos[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                    ReferenceTypeImpl type = referenceType(ci.typeID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                                                           ci.refTypeTag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                                                           ci.signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                    type.setGenericSignature(ci.genericSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                    type.setStatus(ci.status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                retrievedAllTypes = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
    void sendToTarget(Packet packet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        target.send(packet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
    void waitForTargetReply(Packet packet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        target.waitForReply(packet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
         * If any object disposes have been batched up, send them now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        processBatchedDisposes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
    Type findBootType(String signature) throws ClassNotLoadedException {
33835
8cfbdfc35f82 8074696: Remote debugging session hangs for several minutes when calling findBootType
aeriksso
parents: 28059
diff changeset
  1153
        List<ReferenceType> types = retrieveClassesBySignature(signature);
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
  1154
        Iterator<ReferenceType> iter = types.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        while (iter.hasNext()) {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
  1156
            ReferenceType type = iter.next();
33835
8cfbdfc35f82 8074696: Remote debugging session hangs for several minutes when calling findBootType
aeriksso
parents: 28059
diff changeset
  1157
            if (type.classLoader() == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        JNITypeParser parser = new JNITypeParser(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        throw new ClassNotLoadedException(parser.typeName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                                         "Type " + parser.typeName() + " not loaded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    BooleanType theBooleanType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        if (theBooleanType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                if (theBooleanType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                    theBooleanType = new BooleanTypeImpl(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        return theBooleanType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    ByteType theByteType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        if (theByteType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                if (theByteType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                    theByteType = new ByteTypeImpl(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        return theByteType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
    CharType theCharType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        if (theCharType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                if (theCharType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                    theCharType = new CharTypeImpl(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        return theCharType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    ShortType theShortType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        if (theShortType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                if (theShortType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                    theShortType = new ShortTypeImpl(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        return theShortType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
    IntegerType theIntegerType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        if (theIntegerType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                if (theIntegerType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                    theIntegerType = new IntegerTypeImpl(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        return theIntegerType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    LongType theLongType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        if (theLongType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                if (theLongType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                    theLongType = new LongTypeImpl(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        return theLongType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
    FloatType theFloatType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        if (theFloatType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                if (theFloatType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                    theFloatType = new FloatTypeImpl(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        return theFloatType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    DoubleType theDoubleType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        if (theDoubleType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                if (theDoubleType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                    theDoubleType = new DoubleTypeImpl(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        return theDoubleType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
    VoidType theVoidType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        if (theVoidType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                if (theVoidType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                    theVoidType = new VoidTypeImpl(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        return theVoidType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    PrimitiveType primitiveTypeMirror(byte tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
            case JDWP.Tag.BOOLEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                return theBooleanType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
            case JDWP.Tag.BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                return theByteType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            case JDWP.Tag.CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                return theCharType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            case JDWP.Tag.SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                return theShortType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            case JDWP.Tag.INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                return theIntegerType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
            case JDWP.Tag.LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                return theLongType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            case JDWP.Tag.FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                return theFloatType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            case JDWP.Tag.DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                return theDoubleType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                throw new IllegalArgumentException("Unrecognized primitive tag " + tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
    private void processBatchedDisposes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        if (shutdown) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
        JDWP.VirtualMachine.DisposeObjects.Request[] requests = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        synchronized(batchedDisposeRequests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
            int size = batchedDisposeRequests.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
            if (size >= DISPOSE_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                if ((traceFlags & TRACE_OBJREFS) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                    printTrace("Dispose threashold reached. Will dispose "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                               + size + " object references...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                requests = new JDWP.VirtualMachine.DisposeObjects.Request[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                for (int i = 0; i < requests.length; i++) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
  1303
                    SoftObjectReference ref = batchedDisposeRequests.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                    if ((traceFlags & TRACE_OBJREFS) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                        printTrace("Disposing object " + ref.key().longValue() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                                   " (ref count = " + ref.count() + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                    // This is kludgy. We temporarily re-create an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                    // reference so that we can correctly pass its id to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                    // JDWP command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                    requests[i] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                        new JDWP.VirtualMachine.DisposeObjects.Request(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                            new ObjectReferenceImpl(this, ref.key().longValue()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                            ref.count());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                batchedDisposeRequests.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        if (requests != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                JDWP.VirtualMachine.DisposeObjects.process(vm, requests);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
            } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
    private void batchForDispose(SoftObjectReference ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        if ((traceFlags & TRACE_OBJREFS) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            printTrace("Batching object " + ref.key().longValue() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                       " for dispose (ref count = " + ref.count() + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        batchedDisposeRequests.add(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
    private void processQueue() {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
  1338
        Reference<?> ref;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        //if ((traceFlags & TRACE_OBJREFS) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        //    printTrace("Checking for softly reachable objects");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        //}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        while ((ref = referenceQueue.poll()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
            SoftObjectReference softRef = (SoftObjectReference)ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
            removeObjectMirror(softRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
            batchForDispose(softRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
    synchronized ObjectReferenceImpl objectMirror(long id, int tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        // Handle any queue elements that are not strongly reachable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        processQueue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        if (id == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
        ObjectReferenceImpl object = null;
25186
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 24969
diff changeset
  1358
        Long key = id;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        /*
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 27957
diff changeset
  1361
         * Attempt to retrieve an existing object reference
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        SoftObjectReference ref = objectsByID.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        if (ref != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
            object = ref.object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
         * If the object wasn't in the table, or it's soft reference was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
         * cleared, create a new instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        if (object == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
            switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                case JDWP.Tag.OBJECT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                    object = new ObjectReferenceImpl(vm, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                case JDWP.Tag.STRING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                    object = new StringReferenceImpl(vm, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                case JDWP.Tag.ARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                    object = new ArrayReferenceImpl(vm, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                case JDWP.Tag.THREAD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                    ThreadReferenceImpl thread =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                        new ThreadReferenceImpl(vm, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
                    thread.addListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                    object = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                case JDWP.Tag.THREAD_GROUP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                    object = new ThreadGroupReferenceImpl(vm, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                case JDWP.Tag.CLASS_LOADER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                    object = new ClassLoaderReferenceImpl(vm, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                case JDWP.Tag.CLASS_OBJECT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                    object = new ClassObjectReferenceImpl(vm, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                    throw new IllegalArgumentException("Invalid object tag: " + tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
            ref = new SoftObjectReference(key, object, referenceQueue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
             * If there was no previous entry in the table, we add one here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
             * If the previous entry was cleared, we replace it here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
            objectsByID.put(key, ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
            if ((traceFlags & TRACE_OBJREFS) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                printTrace("Creating new " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                           object.getClass().getName() + " (id = " + id + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
            ref.incrementCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        return object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    synchronized void removeObjectMirror(ObjectReferenceImpl object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        // Handle any queue elements that are not strongly reachable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        processQueue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
25186
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 24969
diff changeset
  1423
        SoftObjectReference ref = objectsByID.remove(object.ref());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
        if (ref != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
            batchForDispose(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
             * If there's a live ObjectReference about, it better be part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
             * of the cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            throw new InternalException("ObjectReference " + object.ref() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
                                        " not found in object cache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
    synchronized void removeObjectMirror(SoftObjectReference ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
         * This will remove the soft reference if it has not been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
         * replaced in the cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        objectsByID.remove(ref.key());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
    ObjectReferenceImpl objectMirror(long id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        return objectMirror(id, JDWP.Tag.OBJECT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
    StringReferenceImpl stringMirror(long id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
        return (StringReferenceImpl)objectMirror(id, JDWP.Tag.STRING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
    ArrayReferenceImpl arrayMirror(long id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
       return (ArrayReferenceImpl)objectMirror(id, JDWP.Tag.ARRAY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
    ThreadReferenceImpl threadMirror(long id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
        return (ThreadReferenceImpl)objectMirror(id, JDWP.Tag.THREAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
    ThreadGroupReferenceImpl threadGroupMirror(long id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        return (ThreadGroupReferenceImpl)objectMirror(id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
                                                      JDWP.Tag.THREAD_GROUP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
    ClassLoaderReferenceImpl classLoaderMirror(long id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
        return (ClassLoaderReferenceImpl)objectMirror(id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
                                                      JDWP.Tag.CLASS_LOADER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
    ClassObjectReferenceImpl classObjectMirror(long id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        return (ClassObjectReferenceImpl)objectMirror(id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
                                                      JDWP.Tag.CLASS_OBJECT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1475
    ModuleReferenceImpl moduleMirror(long id) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1476
        return (ModuleReferenceImpl)getModule(id);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1477
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 33835
diff changeset
  1478
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     * Implementation of PathSearchingVirtualMachine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
    private JDWP.VirtualMachine.ClassPaths getClasspath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
        if (pathInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                pathInfo = JDWP.VirtualMachine.ClassPaths.process(vm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
            } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
                throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        return pathInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
   public List<String> classPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
       return Arrays.asList(getClasspath().classpaths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
   public List<String> bootClassPath() {
38332
95dd1e0f418f 8152847: JDI use of sun.boot.class.path needs to be updated for Jigsaw
dsamersoff
parents: 36511
diff changeset
  1498
       return Collections.emptyList();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
   public String baseDirectory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
       return getClasspath().baseDir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
    public void setDefaultStratum(String stratum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        defaultStratum = stratum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        if (stratum == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            stratum = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
            JDWP.VirtualMachine.SetDefaultStratum.process(vm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                                                          stratum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        } catch (JDWPException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
            throw exc.toJDIException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
    public String getDefaultStratum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        return defaultStratum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
    ThreadGroup threadGroupForJDI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
        return threadGroupForJDI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
   static private class SoftObjectReference extends SoftReference<ObjectReferenceImpl> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
       int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
       Long key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
       SoftObjectReference(Long key, ObjectReferenceImpl mirror,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                           ReferenceQueue<ObjectReferenceImpl> queue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
           super(mirror, queue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
           this.count = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
           this.key = key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
       int count() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
           return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
       void incrementCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
           count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
       Long key() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
           return key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
       ObjectReferenceImpl object() {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
  1550
           return get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
}