dart-sdk/runtime/vm/custom_isolate_test.cc

351 lines
9.4 KiB
C++
Raw Normal View History

Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "include/dart_api.h"
#include "include/dart_native_api.h"
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
#include "vm/unit_test.h"
// Custom Isolate Test.
//
// This mid-size test uses the Dart Embedding Api to create a custom
// isolate abstraction. Instead of having a dedicated thread for each
// isolate, as is the case normally, this implementation shares a
// single thread among the isolates using an event queue.
namespace dart {
DECLARE_FLAG(bool, trace_shutdown);
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
static void native_echo(Dart_NativeArguments args);
static void CustomIsolateImpl_start(Dart_NativeArguments args);
static Dart_NativeFunction NativeLookup(Dart_Handle name,
int argc,
bool* auto_setup_scope);
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
static const char* kCustomIsolateScriptChars =
"import 'dart:isolate';\n"
isolates refactor: this change introduces 'dart:isolate' as a library. This is a big global change, so let me explain in more detail. This refactoring CL does the following: - moves all the dart code for isolates in a common library (lib/isolate) - changes frog to understand 'dart:isolate' imoprts by loading the code from the location above. - changes the vm to undernstand 'dart:isolate' imports by creating a separate library that is part of the bootstrap. This follows the same code-structure that Todd suggested in his CL introducing the mirror library - changes dartc to use the shared isolate library as the source of truth for type checking. I left around some of the internal js code in dartc so that the backend continues to work for apps that don't use isolates. - changes all tests that use isolates to import the library explicitly (this is a large bulk of the files in this CL) - changes test status for tests we can't fix in this repo (e.g. co19) - splits the isolate library code to make it possible to preserve some tests without exposing internal types (e.g. tests about serialization/deserialization) - changes the create_sdk script to copy the isolate library to the sdk - includes the isolate library in dartdoc I'll wait for at least one lgtm from each area (dartc, vm, frog, sdk) There is one important pending thing this CL doesn't do: - update test_runner.dart: This should be updated next time we upload the new binaries to tool/testing/bin - dartium specific changes: Vijay, is there anything I need to do for dartium? Review URL: https://chromiumcodereview.appspot.com//9422019 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4647 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-27 22:50:44 +00:00
"\n"
"final RawReceivePort mainPort = new RawReceivePort();\n"
"final SendPort mainSendPort = mainPort.sendPort;\n"
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
"\n"
"echo(arg) native \"native_echo\";\n"
"\n"
"class CustomIsolateImpl implements CustomIsolate {\n"
" CustomIsolateImpl(String entry) : _entry = entry{\n"
" echo('Constructing isolate');\n"
" }\n"
"\n"
" SendPort spawn() {\n"
" return _start(_entry);\n"
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
" }\n"
"\n"
" static SendPort _start(entry)\n"
" native \"CustomIsolateImpl_start\";\n"
"\n"
" String _entry;\n"
"}\n"
"\n"
"abstract class CustomIsolate {\n"
" factory CustomIsolate(String entry) = CustomIsolateImpl;\n"
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
"\n"
" SendPort spawn();\n"
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
"}\n"
"\n"
"isolateMain() {\n"
" echo('Running isolateMain');\n"
" mainPort.handler = (message) {\n"
" var data = message[0];\n"
" var replyTo = message[1];\n"
" echo('Received: $data');\n"
" replyTo.send(data + 1);\n"
" mainPort.close();\n"
" };\n"
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
"}\n"
"\n"
"main() {\n"
" var isolate = new CustomIsolate(\"isolateMain\");\n"
" var receivePort = new RawReceivePort();\n"
" SendPort port = isolate.spawn();\n"
" port.send([42, receivePort.sendPort]);\n"
" receivePort.handler = (message) {\n"
" receivePort.close();\n"
" echo('Received: $message');\n"
" };\n"
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
" return 'success';\n"
"}\n";
// An entry in our event queue.
class Event {
protected:
explicit Event(Dart_Isolate isolate) : isolate_(isolate), next_(NULL) {}
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
public:
virtual ~Event() {}
virtual void Process() = 0;
Dart_Isolate isolate() const { return isolate_; }
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
private:
friend class EventQueue;
Dart_Isolate isolate_;
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
Event* next_;
};
// A simple event queue for our test.
class EventQueue {
public:
EventQueue() { head_ = NULL; }
void Add(Event* event) {
if (head_ == NULL) {
head_ = event;
tail_ = event;
} else {
tail_->next_ = event;
tail_ = event;
}
}
Event* Get() {
if (head_ == NULL) {
return NULL;
}
Event* tmp = head_;
head_ = head_->next_;
if (head_ == NULL) {
// Not necessary, but why not.
tail_ = NULL;
}
return tmp;
}
void RemoveEventsForIsolate(Dart_Isolate isolate) {
Event* cur = head_;
Event* prev = NULL;
while (cur != NULL) {
Event* next = cur->next_;
if (cur->isolate() == isolate) {
// Remove matching event.
if (prev != NULL) {
prev->next_ = next;
} else {
head_ = next;
}
delete cur;
} else {
// Advance.
prev = cur;
}
cur = next;
}
tail_ = prev;
}
private:
Event* head_;
Event* tail_;
};
EventQueue* event_queue;
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
// Start an isolate.
class StartEvent : public Event {
public:
StartEvent(Dart_Isolate isolate, const char* main)
: Event(isolate), main_(main) {}
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
virtual void Process();
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
private:
const char* main_;
};
void StartEvent::Process() {
OS::PrintErr(">> StartEvent with isolate(%p)--\n", isolate());
Dart_EnterIsolate(isolate());
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
Dart_EnterScope();
Dart_Handle result;
Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url()));
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
EXPECT_VALID(lib);
result = Dart_Invoke(lib, NewString(main_), 0, NULL);
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
EXPECT_VALID(result);
free(const_cast<char*>(main_));
main_ = NULL;
Dart_SetMessageNotifyCallback(NULL);
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
Dart_ExitScope();
Dart_ExitIsolate();
}
// Notify an isolate of a pending message.
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
class MessageEvent : public Event {
public:
explicit MessageEvent(Dart_Isolate isolate) : Event(isolate) {}
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
~MessageEvent() {}
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
virtual void Process();
};
void MessageEvent::Process() {
OS::PrintErr("$$ MessageEvent with isolate(%p)\n", isolate());
Dart_EnterIsolate(isolate());
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
Dart_EnterScope();
Dart_Handle result = Dart_HandleMessage();
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
EXPECT_VALID(result);
if (!Dart_HasLivePorts()) {
OS::PrintErr("<< Shutting down isolate(%p)\n", isolate());
event_queue->RemoveEventsForIsolate(isolate());
Dart_SetMessageNotifyCallback(NULL);
Dart_ExitScope();
Dart_ShutdownIsolate();
} else {
Dart_ExitScope();
Dart_ExitIsolate();
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
}
ASSERT(Dart_CurrentIsolate() == NULL);
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
}
static void NotifyMessage(Dart_Isolate dest_isolate) {
OS::PrintErr("-- Notify isolate(%p) of pending message --\n", dest_isolate);
OS::PrintErr("-- Adding MessageEvent to queue --\n");
event_queue->Add(new MessageEvent(dest_isolate));
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
}
static Dart_NativeFunction NativeLookup(Dart_Handle name,
int argc,
bool* auto_setup_scope) {
ASSERT(auto_setup_scope != NULL);
*auto_setup_scope = true;
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
const char* name_str = NULL;
EXPECT(Dart_IsString(name));
EXPECT_VALID(Dart_StringToCString(name, &name_str));
if (strcmp(name_str, "native_echo") == 0) {
return &native_echo;
} else if (strcmp(name_str, "CustomIsolateImpl_start") == 0) {
return &CustomIsolateImpl_start;
}
return NULL;
}
char* saved_echo = NULL;
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
static void native_echo(Dart_NativeArguments args) {
Dart_EnterScope();
Dart_Handle arg = Dart_GetNativeArgument(args, 0);
Dart_Handle toString = Dart_ToString(arg);
EXPECT_VALID(toString);
const char* c_str = NULL;
EXPECT_VALID(Dart_StringToCString(toString, &c_str));
if (saved_echo != nullptr) {
free(saved_echo);
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
}
saved_echo = strdup(c_str);
OS::PrintErr("-- (isolate=%p) %s\n", Dart_CurrentIsolate(), c_str);
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
Dart_ExitScope();
}
static void CustomIsolateImpl_start(Dart_NativeArguments args) {
OS::PrintErr("-- Enter: CustomIsolateImpl_start --\n");
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
// We would probably want to pass in the this pointer too, so we
// could associate the CustomIsolateImpl instance with the
// Dart_Isolate by storing it in a native field.
EXPECT_EQ(1, Dart_GetNativeArgumentCount(args));
Dart_Handle param = Dart_GetNativeArgument(args, 0);
EXPECT_VALID(param);
EXPECT(Dart_IsString(param));
const char* isolate_main = NULL;
EXPECT_VALID(Dart_StringToCString(param, &isolate_main));
isolate_main = strdup(isolate_main);
// Save current isolate.
Dart_Isolate saved_isolate = Dart_CurrentIsolate();
Dart_ExitIsolate();
// Create a new Dart_Isolate.
Dart_Isolate new_isolate = TestCase::CreateTestIsolate();
EXPECT(new_isolate != NULL);
Dart_SetMessageNotifyCallback(&NotifyMessage);
Dart_EnterScope();
// Reload all the test classes here.
//
// TODO(turnidge): Use the create isolate callback instead?
Dart_Handle lib =
TestCase::LoadTestScript(kCustomIsolateScriptChars, NativeLookup);
EXPECT_VALID(lib);
Dart_Handle main_send_port = Dart_GetField(lib, NewString("mainSendPort"));
EXPECT_VALID(main_send_port);
Dart_Port main_port_id;
Dart_Handle err = Dart_SendPortGetId(main_send_port, &main_port_id);
EXPECT_VALID(err);
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
OS::PrintErr("-- Adding StartEvent to queue --\n");
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
event_queue->Add(new StartEvent(new_isolate, isolate_main));
// Restore the original isolate.
Dart_ExitScope();
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
Dart_ExitIsolate();
Dart_EnterIsolate(saved_isolate);
Dart_EnterScope();
Dart_Handle send_port = Dart_NewSendPort(main_port_id);
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
EXPECT_VALID(send_port);
Dart_SetReturnValue(args, send_port);
OS::PrintErr("-- Exit: CustomIsolateImpl_start --\n");
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
Dart_ExitScope();
}
VM_UNIT_TEST_CASE(CustomIsolates) {
bool saved_flag = FLAG_trace_shutdown;
FLAG_trace_shutdown = true;
FLAG_verify_handles = true;
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
event_queue = new EventQueue();
Dart_Isolate dart_isolate = TestCase::CreateTestIsolate();
EXPECT(dart_isolate != NULL);
Dart_SetMessageNotifyCallback(&NotifyMessage);
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
Dart_EnterScope();
Dart_Handle result;
// Create a test library.
Dart_Handle lib =
TestCase::LoadTestScript(kCustomIsolateScriptChars, NativeLookup);
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
EXPECT_VALID(lib);
// Run main.
result = Dart_Invoke(lib, NewString("main"), 0, NULL);
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
EXPECT_VALID(result);
EXPECT(Dart_IsString(result));
const char* result_str = NULL;
EXPECT_VALID(Dart_StringToCString(result, &result_str));
EXPECT_STREQ("success", result_str);
Dart_ExitScope();
Dart_ExitIsolate();
OS::PrintErr("-- Starting event loop --\n");
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
Event* event = event_queue->Get();
while (event != nullptr) {
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
event->Process();
delete event;
event = event_queue->Get();
}
OS::PrintErr("-- Finished event loop --\n");
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
EXPECT_STREQ("Received: 43", saved_echo);
free(saved_echo);
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
delete event_queue;
event_queue = NULL;
FLAG_trace_shutdown = saved_flag;
Add a mid-sized integration test for the Dart Embedding Api which demonstrates how to create a custom isolate abstraction. In this test, we use an event queue to share a single thread among our custom isolates. Add a callback which allows embedders to see when a port is created. Not sure if I should keep this or not. New apis: Dart_CreatePort() -- allocates a port id and adds a port->isolate mapping. Dart_IsolateHasActivePorts() -- does the current isolate have open ports? (this name a bit awkward...) Bail out of PortMap::ClosePorts() early if there are no open ports. This suppresses calls to the close_port_callback when there are no open ports. Use DART_CHECK_VALID to provide better error output when the test lib has errors. ------------------------- Sample output of the test: -- (isolate=0x815600) Constructing isolate -- Enter: CustomIsolateImpl_start -- -- Adding port (7111) -> isolate (0x830800) -- -- Adding StartEvent to queue -- -- Exit: CustomIsolateImpl_start -- -- Adding port (7112) -> isolate (0x815600) -- -- Posting message dest(7111) reply(0) -- -- Adding MessageEvent to queue -- -- Starting event loop -- >> StartEvent with isolate(0x830800)-- -- (isolate=0x830800) Running isolateMain $$ MessageEvent with dest port 7111-- -- (isolate=0x830800) Received: 42 -- Posting message dest(7112) reply(0) -- -- Adding MessageEvent to queue -- $$ MessageEvent with dest port 7112-- -- Closing port (7112) -- -- Adding ShutdownEvent to queue -- -- (isolate=0x815600) Received: 43 << ShutdownEvent with isolate(0x815600)-- -- Finished event loop -- Review URL: http://codereview.chromium.org//8588040 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1906 260f80e4-7a28-3924-810f-c04153c831b5
2011-11-29 21:55:13 +00:00
}
} // namespace dart