Search in sources :

Example 1 with ClassPrepareRequest

use of com.oracle.truffle.espresso.jdwp.impl.ClassPrepareRequest 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)

Aggregations

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