Search in sources :

Example 6 with PacketStream

use of com.oracle.truffle.espresso.jdwp.impl.PacketStream in project graal by oracle.

the class VMEventListenerImpl method threadStarted.

@Override
public void threadStarted(Object thread) {
    if (connection == null || threadStartedRequestId == 0) {
        return;
    }
    PacketStream stream = new PacketStream().commandPacket().commandSet(64).command(100);
    stream.writeByte(threadStartSuspendPolicy);
    suspend(threadStartSuspendPolicy, thread);
    // # events in reply
    stream.writeInt(1);
    stream.writeByte(RequestedJDWPEvents.THREAD_START);
    stream.writeInt(threadStartedRequestId);
    stream.writeLong(ids.getIdAsLong(thread));
    JDWP.LOGGER.fine(() -> "sending thread started event for thread: " + context.getThreadName(thread));
    if (holdEvents) {
        heldEvents.add(stream);
    } else {
        connection.queuePacket(stream);
    }
}
Also used : PacketStream(com.oracle.truffle.espresso.jdwp.impl.PacketStream)

Example 7 with PacketStream

use of com.oracle.truffle.espresso.jdwp.impl.PacketStream in project graal by oracle.

the class VMEventListenerImpl method vmStarted.

public void vmStarted(boolean suspend) {
    PacketStream stream = new PacketStream().commandPacket().commandSet(64).command(100);
    stream.writeByte(suspend ? SuspendStrategy.ALL : SuspendStrategy.NONE);
    stream.writeInt(1);
    stream.writeByte(RequestedJDWPEvents.VM_START);
    stream.writeInt(vmStartRequestId != -1 ? vmStartRequestId : 0);
    stream.writeLong(context.getIds().getIdAsLong(initialThread));
    connection.queuePacket(stream);
}
Also used : PacketStream(com.oracle.truffle.espresso.jdwp.impl.PacketStream)

Example 8 with PacketStream

use of com.oracle.truffle.espresso.jdwp.impl.PacketStream in project graal by oracle.

the class VMEventListenerImpl method classPrepared.

@Override
@TruffleBoundary
public void classPrepared(KlassRef klass, Object prepareThread) {
    if (connection == null) {
        return;
    }
    // prepare the event and ship
    PacketStream stream = new PacketStream().commandPacket().commandSet(64).command(100);
    // check if event should be reported based on the current patterns
    String dotName = klass.getNameAsString().replace('/', '.');
    ClassPrepareRequest[] allClassPrepareRequests = getAllClassPrepareRequests();
    ArrayList<ClassPrepareRequest> toSend = new ArrayList<>();
    byte suspendPolicy = SuspendStrategy.NONE;
    for (ClassPrepareRequest cpr : allClassPrepareRequests) {
        Pattern[] patterns = cpr.getPatterns();
        for (Pattern pattern : patterns) {
            if ("".equals(pattern.pattern()) || pattern.matcher(dotName).matches()) {
                toSend.add(cpr);
                byte cprPolicy = cpr.getSuspendPolicy();
                if (cprPolicy == SuspendStrategy.ALL) {
                    suspendPolicy = SuspendStrategy.ALL;
                } else if (cprPolicy == SuspendStrategy.EVENT_THREAD && suspendPolicy != SuspendStrategy.ALL) {
                    suspendPolicy = SuspendStrategy.EVENT_THREAD;
                }
            }
        }
    }
    if (!toSend.isEmpty()) {
        stream.writeByte(suspendPolicy);
        stream.writeInt(toSend.size());
        for (ClassPrepareRequest cpr : toSend) {
            stream.writeByte(RequestedJDWPEvents.CLASS_PREPARE);
            stream.writeInt(cpr.getRequestId());
            stream.writeLong(ids.getIdAsLong(prepareThread));
            stream.writeByte(TypeTag.getKind(klass));
            stream.writeLong(ids.getIdAsLong(klass));
            stream.writeString(klass.getTypeAsString());
            stream.writeInt(klass.getStatus());
        }
        if (suspendPolicy != SuspendStrategy.NONE) {
            // the current thread has just prepared the class
            // so we must suspend according to suspend policy
            debuggerController.immediateSuspend(prepareThread, suspendPolicy, new Callable<Void>() {

                @Override
                public Void call() {
                    if (holdEvents) {
                        heldEvents.add(stream);
                    } else {
                        JDWP.LOGGER.fine(() -> "SENDING CLASS PREPARE EVENT FOR KLASS: " + klass.getNameAsString() + " WITH THREAD " + context.getThreadName(prepareThread));
                        connection.queuePacket(stream);
                    }
                    return null;
                }
            });
        } else {
            if (holdEvents) {
                heldEvents.add(stream);
            } else {
                connection.queuePacket(stream);
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) PacketStream(com.oracle.truffle.espresso.jdwp.impl.PacketStream) ArrayList(java.util.ArrayList) ClassPrepareRequest(com.oracle.truffle.espresso.jdwp.impl.ClassPrepareRequest) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 9 with PacketStream

use of com.oracle.truffle.espresso.jdwp.impl.PacketStream in project graal by oracle.

the class VMEventListenerImpl method threadDied.

@Override
public void threadDied(Object thread) {
    if (connection == null || threadDeathRequestId == 0) {
        return;
    }
    PacketStream stream = new PacketStream().commandPacket().commandSet(64).command(100);
    stream.writeByte(threadDeathSuspendPolicy);
    suspend(threadDeathSuspendPolicy, thread);
    // # events in reply
    stream.writeInt(1);
    stream.writeByte(RequestedJDWPEvents.THREAD_DEATH);
    stream.writeInt(threadDeathRequestId);
    stream.writeLong(ids.getIdAsLong(thread));
    if (holdEvents) {
        heldEvents.add(stream);
    } else {
        connection.queuePacket(stream);
    }
}
Also used : PacketStream(com.oracle.truffle.espresso.jdwp.impl.PacketStream)

Example 10 with PacketStream

use of com.oracle.truffle.espresso.jdwp.impl.PacketStream in project graal by oracle.

the class VMEventListenerImpl method sendMonitorWaitEvent.

public void sendMonitorWaitEvent(Object monitor, long timeout, RequestFilter filter, CallFrame currentFrame) {
    if (connection == null) {
        return;
    }
    PacketStream stream = new PacketStream().commandPacket().commandSet(64).command(100);
    stream.writeByte(filter.getSuspendPolicy());
    // # events in reply
    stream.writeInt(1);
    stream.writeByte(RequestedJDWPEvents.MONITOR_WAIT);
    stream.writeInt(filter.getRequestId());
    stream.writeLong(currentFrame.getThreadId());
    // tagged object ID
    stream.writeByte(context.getTag(monitor));
    stream.writeLong(context.getIds().getIdAsLong(monitor));
    // location
    stream.writeByte(currentFrame.getTypeTag());
    stream.writeLong(currentFrame.getClassId());
    stream.writeLong(currentFrame.getMethodId());
    long codeIndex = currentFrame.getCodeIndex();
    stream.writeLong(codeIndex);
    // timeout
    stream.writeLong(timeout);
    JDWP.LOGGER.fine(() -> "Sending monitor wait event");
    if (holdEvents) {
        heldEvents.add(stream);
    } else {
        connection.queuePacket(stream);
    }
}
Also used : PacketStream(com.oracle.truffle.espresso.jdwp.impl.PacketStream)

Aggregations

PacketStream (com.oracle.truffle.espresso.jdwp.impl.PacketStream)15 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)1 ClassPrepareRequest (com.oracle.truffle.espresso.jdwp.impl.ClassPrepareRequest)1 FieldBreakpointInfo (com.oracle.truffle.espresso.jdwp.impl.FieldBreakpointInfo)1 MethodBreakpointInfo (com.oracle.truffle.espresso.jdwp.impl.MethodBreakpointInfo)1 ArrayList (java.util.ArrayList)1 Pattern (java.util.regex.Pattern)1