Files
sdk/runtime/vm/port.h
T
Alexander Aprelev 17654b70d7 [vm/isolates] Introduce sendAndExit.
sendAndExit allows for fast data passing from worker isolate back to
parent.

```
                                              | linux x64  | spawnIsolate | sendAndExit |
                                              |us per iter | over sync    | over send   |
                                              +------------+--------------+-------------+
IsolateJson.Decode50KBx1(RunTime):               43,175.000   339.83%
IsolateJson.SendAndExit_Decode50KBx1(RunTime):   22,070.000   124.83%        -48.88%
IsolateJson.SyncDecode50KBx1(RunTime):            9,816.284

IsolateJson.Decode50KBx4(RunTime):               77,630.000   104.56%
IsolateJson.SendAndExit_Decode50KBx4(RunTime):   46,307.000   22.02%         -40.35%
IsolateJson.SyncDecode50KBx4(RunTime):           37,949.528

IsolateJson.Decode100KBx1(RunTime):              71,035.000   270.42%
IsolateJson.SendAndExit_Decode100KBx1(RunTime):  43,056.000   124.52%        -39.39%
IsolateJson.SyncDecode100KBx1(RunTime):          19,176.733

IsolateJson.Decode100KBx4(RunTime):             120,915.000   54.66%
IsolateJson.SendAndExit_Decode100KBx4(RunTime):  67,101.000  -14.17%         -44.51%
IsolateJson.SyncDecode100KBx4(RunTime):          78,179.731

IsolateJson.Decode250KBx1(RunTime):             173,574.000  202.52%
IsolateJson.SendAndExit_Decode250KBx1(RunTime): 103,334.000   80.10%         -40.47%
IsolateJson.SyncDecode250KBx1(RunTime):          57,375.314

IsolateJson.Decode250KBx4(RunTime):             292,118.000   20.30%
IsolateJson.SendAndExit_Decode250KBx4(RunTime): 168,444.000  -30.63%         -42.34%
IsolateJson.SyncDecode250KBx4(RunTime):         242,831.000

IsolateJson.Decode1MBx1(RunTime):               631,578.000  166.34%
IsolateJson.SendAndExit_Decode1MBx1(RunTime):   371,127.000   56.50%         -41.24%
IsolateJson.SyncDecode1MBx1(RunTime):           237,135.778

IsolateJson.Decode1MBx4(RunTime):             1,322,789.000   36.16%
IsolateJson.SendAndExit_Decode1MBx4(RunTime):   657,179.000  -32.35%         -50.32%
IsolateJson.SyncDecode1MBx4(RunTime):           971,473.333

```

Bug: https://github.com/dart-lang/sdk/issues/37835
Bug: https://github.com/dart-lang/sdk/issues/36097
Change-Id: I386641e1431ed9f2e34fac36f562607a666ee4a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142823
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-04-22 17:34:09 +00:00

102 lines
2.8 KiB
C++

// 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.
#ifndef RUNTIME_VM_PORT_H_
#define RUNTIME_VM_PORT_H_
#include <memory>
#include "include/dart_api.h"
#include "vm/allocation.h"
#include "vm/globals.h"
#include "vm/json_stream.h"
#include "vm/port_set.h"
#include "vm/random.h"
namespace dart {
class Isolate;
class Message;
class MessageHandler;
class Mutex;
class PortMapTestPeer;
class PortMap : public AllStatic {
public:
enum PortState {
kNewPort = 0, // a newly allocated port
kLivePort = 1, // a regular port (has a ReceivePort)
kControlPort = 2, // a special control port (has a ReceivePort)
};
// Allocate a port for the provided handler and return its VM-global id.
static Dart_Port CreatePort(MessageHandler* handler);
// Indicates that a port has had a ReceivePort created for it at the
// dart language level. The port remains live until it is closed.
static void SetPortState(Dart_Port id, PortState kind);
// Close the port with id. All pending messages will be dropped.
//
// Returns true if the port is successfully closed.
static bool ClosePort(Dart_Port id);
// Close all the ports for the provided handler.
static void ClosePorts(MessageHandler* handler);
// Enqueues the message in the port with id. Returns false if the port is not
// active any longer.
//
// Claims ownership of 'message'.
static bool PostMessage(std::unique_ptr<Message> message,
bool before_events = false);
// Returns whether a port is local to the current isolate.
static bool IsLocalPort(Dart_Port id);
// Returns the owning Isolate for port 'id'.
static Isolate* GetIsolate(Dart_Port id);
static bool IsReceiverInThisIsolateGroup(Dart_Port receiver,
IsolateGroup* group);
static void Init();
static void Cleanup();
static void PrintPortsForMessageHandler(MessageHandler* handler,
JSONStream* stream);
static void DebugDumpForMessageHandler(MessageHandler* handler);
private:
friend class dart::PortMapTestPeer;
struct Entry : public PortSet<Entry>::Entry {
Entry() : handler(nullptr), state(kNewPort) {}
MessageHandler* handler;
PortState state;
};
static const char* PortStateString(PortState state);
// Allocate a new unique port.
static Dart_Port AllocatePort();
static bool IsActivePort(Dart_Port id);
static bool IsLivePort(Dart_Port id);
// Lock protecting access to the port map.
static Mutex* mutex_;
static PortSet<Entry>* ports_;
static MessageHandler* deleted_entry_;
static Random* prng_;
};
} // namespace dart
#endif // RUNTIME_VM_PORT_H_