Search in sources :

Example 1 with RemoteObjectsHandler

use of com.oracle.truffle.tools.chromeinspector.RemoteObjectsHandler in project graal by oracle.

the class TestMemoryLeaks method testRemoteObjectsLeak.

@Test
public void testRemoteObjectsLeak() throws Exception {
    InspectorTester tester = InspectorTester.start(false);
    RemoteObjectsHandler remoteObjectsHandler = tester.getInspectorContext().getRemoteObjectsHandler();
    assertEmptyRemoteObjectsMaps(remoteObjectsHandler);
    Source source = Source.newBuilder("sl", "function main() {\n" + "  func1();\n" + "  func2(new());\n" + "  func3();\n" + "}\n" + "function func1() {\n" + "  a = 0;\n" + "  b = new();\n" + "  debugger;\n" + "}\n" + "function func2(arg) {\n" + "  c = new();\n" + "  d = 3;\n" + "  debugger;\n" + "}\n" + "function func3() {\n" + "  debugger;\n" + "}\n", "code").build();
    String slTestURI = InspectorTester.getStringURI(source.getURI());
    tester.sendMessage("{\"id\":1,\"method\":\"Runtime.enable\"}");
    tester.sendMessage("{\"id\":2,\"method\":\"Debugger.enable\"}");
    tester.sendMessage("{\"id\":3,\"method\":\"Runtime.runIfWaitingForDebugger\"}");
    assertTrue(tester.compareReceivedMessages("" + "{\"result\":{},\"id\":1}\n" + "{\"result\":{},\"id\":2}\n" + "{\"result\":{},\"id\":3}\n" + "{\"method\":\"Runtime.executionContextCreated\",\"params\":{\"context\":{\"origin\":\"\",\"name\":\"test\",\"id\":1}}}\n"));
    tester.eval(source);
    // Suspend in func1:
    tester.receiveMessages("{\"method\":\"Debugger.scriptParsed\"", "{\"method\":\"Debugger.paused\"", "\"url\":\"" + slTestURI + "\"}]}}\n");
    tester.sendMessage("{\"id\":5,\"method\":\"Runtime.getProperties\",\"params\":{\"objectId\":\"1\"}}");
    tester.receiveMessages("{\"result\":", "\"name\":\"a\"", "\"name\":\"b\"", "\"id\":5}\n");
    // global, func1, func2, func3, b
    assertRemoteObjectsMapsSize(remoteObjectsHandler, 5);
    tester.sendMessage("{\"id\":10,\"method\":\"Debugger.resume\"}");
    assertTrue(tester.compareReceivedMessages("" + "{\"result\":{},\"id\":10}\n" + "{\"method\":\"Debugger.resumed\"}\n"));
    // Suspend in func2:
    tester.receiveMessages("{\"method\":\"Debugger.paused\"", "\"url\":\"" + slTestURI + "\"}]}}\n");
    tester.sendMessage("{\"id\":15,\"method\":\"Runtime.getProperties\",\"params\":{\"objectId\":\"6\"}}");
    tester.receiveMessages("{\"result\":", "\"name\":\"arg\"", "\"name\":\"c\"", "\"name\":\"d\"", "\"id\":15}\n");
    // global, func1, func2, func3, arg, c
    assertRemoteObjectsMapsSize(remoteObjectsHandler, 6);
    tester.sendMessage("{\"id\":20,\"method\":\"Debugger.resume\"}");
    assertTrue(tester.compareReceivedMessages("" + "{\"result\":{},\"id\":20}\n" + "{\"method\":\"Debugger.resumed\"}\n"));
    // Suspend in func3:
    tester.receiveMessages("{\"method\":\"Debugger.paused\"", "\"url\":\"" + slTestURI + "\"}]}}\n");
    tester.sendMessage("{\"id\":25,\"method\":\"Runtime.getProperties\",\"params\":{\"objectId\":\"12\"}}");
    assertTrue(tester.compareReceivedMessages("{\"result\":{\"result\":[],\"internalProperties\":[]},\"id\":25}\n"));
    // global, func1, func2, func3
    assertRemoteObjectsMapsSize(remoteObjectsHandler, 4);
    // Finish
    tester.sendMessage("{\"id\":30,\"method\":\"Debugger.resume\"}");
    assertTrue(tester.compareReceivedMessages("" + "{\"result\":{},\"id\":30}\n" + "{\"method\":\"Debugger.resumed\"}\n"));
    tester.finishNoGC();
    assertEmptyRemoteObjectsMaps(remoteObjectsHandler);
    remoteObjectsHandler = null;
    tester.finish();
}
Also used : RemoteObjectsHandler(com.oracle.truffle.tools.chromeinspector.RemoteObjectsHandler) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 2 with RemoteObjectsHandler

use of com.oracle.truffle.tools.chromeinspector.RemoteObjectsHandler in project graal by oracle.

the class CustomPreview method createJSON.

private static JSONObject createJSON(DebugValue debugValue, DebugValue config, DebugValue headerValue, DebugValue bodyFunction, InspectorExecutionContext context) {
    JSONObject json = new JSONObject();
    json.put(HEADER, value2JSON(headerValue, context).toString());
    if (bodyFunction != null) {
        RemoteObject bodyFunctionRemote = context.getRemoteObjectsHandler().getRemote(bodyFunction);
        RemoteObjectsHandler objectsHandler = context.getRemoteObjectsHandler();
        objectsHandler.registerCustomPreviewBody(bodyFunctionRemote.getId(), bodyFunction);
        if (config != null) {
            // If there is an config object, register it for callFunctionOn() call.
            String objectId = objectsHandler.getRemote(debugValue).getId();
            objectsHandler.registerCustomPreviewConfig(objectId, config);
        }
        json.put(BODY_GETTER_ID, bodyFunctionRemote.getId());
    }
    return json;
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) RemoteObjectsHandler(com.oracle.truffle.tools.chromeinspector.RemoteObjectsHandler)

Aggregations

RemoteObjectsHandler (com.oracle.truffle.tools.chromeinspector.RemoteObjectsHandler)2 JSONObject (com.oracle.truffle.tools.utils.json.JSONObject)1 Source (org.graalvm.polyglot.Source)1 Test (org.junit.Test)1