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