void RequestManager::ControlWatchpoint()

in modules/jpda/src/main/native/jdwp/common/agent/core/RequestManager.cpp [175:233]


void RequestManager::ControlWatchpoint(JNIEnv* jni,
        AgentEventRequest* request, bool enable)
    throw(AgentException)
{
    JDWP_TRACE_ENTRY("ControlWatchpoint(" << jni << ',' << request << ',' << enable << ")");

    FieldOnlyModifier *fom = request->GetField();
    if (fom == 0) {
        throw InternalErrorException();
    }
    jclass cls = fom->GetClass();
    jfieldID field = fom->GetField();
    bool found = false;
    RequestList& rl = GetRequestList(request->GetEventKind());
    for (RequestListIterator i = rl.begin(); i != rl.end(); i++) {
        AgentEventRequest* req = *i;
        FieldOnlyModifier *m = req->GetField();
        if (m != 0 && field == m->GetField() &&
            JNI_TRUE == jni->IsSameObject(cls, m->GetClass()))
        {
            found = true;
            break;
        }
    }
    if (!found) {
        JDWP_TRACE_EVENT("ControlWatchpoint: watchpoint "
            << GetEventKindName(request->GetEventKind())
            << "[" << request->GetEventKind() << "] "
            << (enable ? "set" : "clear") << ", field=" << field);
        jvmtiError err;
        if (request->GetEventKind() == JDWP_EVENT_FIELD_ACCESS) {
            if (enable) {
                JVMTI_TRACE(err, GetJvmtiEnv()->SetFieldAccessWatch(cls, field));
            } else {
                JVMTI_TRACE(err, GetJvmtiEnv()->ClearFieldAccessWatch(cls, field));
            }
        } else if (request->GetEventKind() == JDWP_EVENT_FIELD_MODIFICATION) {
            if (enable) {
                JVMTI_TRACE(err, GetJvmtiEnv()->SetFieldModificationWatch(cls, field));
            } else {
                JVMTI_TRACE(err, GetJvmtiEnv()->ClearFieldModificationWatch(cls, field));
            }
        } else {
            throw InternalErrorException();
        }
        if (err != JVMTI_ERROR_NONE) {
            throw AgentException(err);
        }
#ifndef NDEBUG
        if (JDWP_TRACE_ENABLED(LOG_KIND_EVENT)) {
            char* name = 0;
            JVMTI_TRACE(err, GetJvmtiEnv()->GetFieldName(cls, field, &name, 0, 0));
            JvmtiAutoFree af(name);
            JDWP_TRACE_EVENT("ControlBreakpoint: request: field=" << name 
                << " kind=" << request->GetEventKind() << " enable=" << enable);
        }
#endif // NDEBUG
    }
}