2011-10-05 05:20:07 +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.
|
|
|
|
|
2016-10-26 07:26:03 +00:00
|
|
|
#ifndef RUNTIME_VM_DART_H_
|
|
|
|
#define RUNTIME_VM_DART_H_
|
2011-10-05 05:20:07 +00:00
|
|
|
|
|
|
|
#include "include/dart_api.h"
|
|
|
|
#include "vm/allocation.h"
|
2016-05-05 01:47:36 +00:00
|
|
|
#include "vm/snapshot.h"
|
2011-10-05 05:20:07 +00:00
|
|
|
|
|
|
|
namespace dart {
|
|
|
|
|
|
|
|
// Forward declarations.
|
|
|
|
class DebugInfo;
|
|
|
|
class Isolate;
|
2015-06-17 19:46:32 +00:00
|
|
|
class LocalHandle;
|
2012-02-02 19:05:06 +00:00
|
|
|
class RawError;
|
2012-12-21 02:33:05 +00:00
|
|
|
class ReadOnlyHandles;
|
2012-04-19 19:47:27 +00:00
|
|
|
class ThreadPool;
|
2016-11-23 08:26:15 +00:00
|
|
|
namespace kernel {
|
|
|
|
class Program;
|
|
|
|
}
|
2011-10-05 05:20:07 +00:00
|
|
|
|
|
|
|
class Dart : public AllStatic {
|
|
|
|
public:
|
2018-10-11 16:52:14 +00:00
|
|
|
// Returns null if initialization succeeds, otherwise returns an error message
|
|
|
|
// (caller owns error message and has to free it).
|
2018-09-28 23:18:59 +00:00
|
|
|
static char* Init(const uint8_t* vm_snapshot_data,
|
|
|
|
const uint8_t* vm_snapshot_instructions,
|
2019-07-08 23:49:05 +00:00
|
|
|
Dart_IsolateGroupCreateCallback create_group,
|
|
|
|
Dart_InitializeIsolateCallback initialize_isolate,
|
2018-09-28 23:18:59 +00:00
|
|
|
Dart_IsolateShutdownCallback shutdown,
|
|
|
|
Dart_IsolateCleanupCallback cleanup,
|
2019-07-08 23:49:05 +00:00
|
|
|
Dart_IsolateGroupCleanupCallback cleanup_group,
|
2018-09-28 23:18:59 +00:00
|
|
|
Dart_ThreadExitCallback thread_exit,
|
|
|
|
Dart_FileOpenCallback file_open,
|
|
|
|
Dart_FileReadCallback file_read,
|
|
|
|
Dart_FileWriteCallback file_write,
|
|
|
|
Dart_FileCloseCallback file_close,
|
|
|
|
Dart_EntropySource entropy_source,
|
|
|
|
Dart_GetVMServiceAssetsArchive get_service_assets,
|
2019-06-24 15:42:43 +00:00
|
|
|
bool start_kernel_isolate,
|
|
|
|
Dart_CodeObserver* observer);
|
2018-10-11 16:52:14 +00:00
|
|
|
|
|
|
|
// Returns null if cleanup succeeds, otherwise returns an error message
|
|
|
|
// (caller owns error message and has to free it).
|
|
|
|
static char* Cleanup();
|
2011-10-05 05:20:07 +00:00
|
|
|
|
2015-06-07 15:57:34 +00:00
|
|
|
static Isolate* CreateIsolate(const char* name_prefix,
|
2019-07-11 12:13:43 +00:00
|
|
|
const Dart_IsolateFlags& api_flags,
|
|
|
|
IsolateGroup* isolate_group);
|
2016-11-16 12:56:20 +00:00
|
|
|
|
|
|
|
// Initialize an isolate, either from a snapshot, from a Kernel binary, or
|
|
|
|
// from SDK library sources. If the snapshot_buffer is non-NULL,
|
|
|
|
// initialize from a snapshot or a Kernel binary depending on the value of
|
|
|
|
// from_kernel. Otherwise, initialize from sources.
|
2017-01-23 18:25:02 +00:00
|
|
|
static RawError* InitializeIsolate(const uint8_t* snapshot_data,
|
|
|
|
const uint8_t* snapshot_instructions,
|
2018-04-27 17:42:16 +00:00
|
|
|
const uint8_t* shared_data,
|
|
|
|
const uint8_t* shared_instructions,
|
2018-05-14 20:58:08 +00:00
|
|
|
const uint8_t* kernel_buffer,
|
|
|
|
intptr_t kernel_buffer_size,
|
2016-11-16 12:56:20 +00:00
|
|
|
void* data);
|
2013-07-09 14:59:01 +00:00
|
|
|
static void RunShutdownCallback();
|
2015-11-02 22:29:16 +00:00
|
|
|
static void ShutdownIsolate(Isolate* isolate);
|
2011-10-05 05:20:07 +00:00
|
|
|
static void ShutdownIsolate();
|
|
|
|
|
|
|
|
static Isolate* vm_isolate() { return vm_isolate_; }
|
2012-04-19 19:47:27 +00:00
|
|
|
static ThreadPool* thread_pool() { return thread_pool_; }
|
2011-10-05 05:20:07 +00:00
|
|
|
|
2016-12-15 22:34:04 +00:00
|
|
|
static int64_t UptimeMicros();
|
|
|
|
static int64_t UptimeMillis() {
|
|
|
|
return UptimeMicros() / kMicrosecondsPerMillisecond;
|
|
|
|
}
|
2016-02-12 19:09:23 +00:00
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
static void set_pprof_symbol_generator(DebugInfo* value) {
|
|
|
|
pprof_symbol_generator_ = value;
|
|
|
|
}
|
|
|
|
static DebugInfo* pprof_symbol_generator() { return pprof_symbol_generator_; }
|
|
|
|
|
2015-06-17 19:46:32 +00:00
|
|
|
static LocalHandle* AllocateReadOnlyApiHandle();
|
2015-06-22 14:19:56 +00:00
|
|
|
static bool IsReadOnlyApiHandle(Dart_Handle handle);
|
2015-06-17 19:46:32 +00:00
|
|
|
|
2012-12-21 02:33:05 +00:00
|
|
|
static uword AllocateReadOnlyHandle();
|
|
|
|
static bool IsReadOnlyHandle(uword address);
|
|
|
|
|
2018-02-14 23:27:38 +00:00
|
|
|
static const char* FeaturesString(Isolate* isolate,
|
|
|
|
bool is_vm_snapshot,
|
|
|
|
Snapshot::Kind kind);
|
2017-01-23 18:25:02 +00:00
|
|
|
static Snapshot::Kind vm_snapshot_kind() { return vm_snapshot_kind_; }
|
2016-02-15 08:15:26 +00:00
|
|
|
|
2016-03-17 20:40:20 +00:00
|
|
|
static Dart_ThreadExitCallback thread_exit_callback() {
|
|
|
|
return thread_exit_callback_;
|
|
|
|
}
|
|
|
|
static void set_thread_exit_callback(Dart_ThreadExitCallback cback) {
|
|
|
|
thread_exit_callback_ = cback;
|
|
|
|
}
|
|
|
|
static void SetFileCallbacks(Dart_FileOpenCallback file_open,
|
|
|
|
Dart_FileReadCallback file_read,
|
|
|
|
Dart_FileWriteCallback file_write,
|
|
|
|
Dart_FileCloseCallback file_close) {
|
|
|
|
file_open_callback_ = file_open;
|
|
|
|
file_read_callback_ = file_read;
|
|
|
|
file_write_callback_ = file_write;
|
|
|
|
file_close_callback_ = file_close;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Dart_FileOpenCallback file_open_callback() {
|
|
|
|
return file_open_callback_;
|
|
|
|
}
|
|
|
|
static Dart_FileReadCallback file_read_callback() {
|
|
|
|
return file_read_callback_;
|
|
|
|
}
|
|
|
|
static Dart_FileWriteCallback file_write_callback() {
|
|
|
|
return file_write_callback_;
|
|
|
|
}
|
|
|
|
static Dart_FileCloseCallback file_close_callback() {
|
|
|
|
return file_close_callback_;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_entropy_source_callback(Dart_EntropySource entropy_source) {
|
|
|
|
entropy_source_callback_ = entropy_source;
|
|
|
|
}
|
|
|
|
static Dart_EntropySource entropy_source_callback() {
|
|
|
|
return entropy_source_callback_;
|
|
|
|
}
|
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
private:
|
2015-09-15 19:49:52 +00:00
|
|
|
static void WaitForIsolateShutdown();
|
2016-06-10 23:00:18 +00:00
|
|
|
static void WaitForApplicationIsolateShutdown();
|
2018-07-11 19:29:15 +00:00
|
|
|
static bool HasApplicationIsolateLocked();
|
2015-09-15 19:49:52 +00:00
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
static Isolate* vm_isolate_;
|
2016-12-15 22:34:04 +00:00
|
|
|
static int64_t start_time_micros_;
|
2012-04-19 19:47:27 +00:00
|
|
|
static ThreadPool* thread_pool_;
|
2011-10-05 05:20:07 +00:00
|
|
|
static DebugInfo* pprof_symbol_generator_;
|
2012-12-21 02:33:05 +00:00
|
|
|
static ReadOnlyHandles* predefined_handles_;
|
2017-01-23 18:25:02 +00:00
|
|
|
static Snapshot::Kind vm_snapshot_kind_;
|
2016-03-17 20:40:20 +00:00
|
|
|
static Dart_ThreadExitCallback thread_exit_callback_;
|
|
|
|
static Dart_FileOpenCallback file_open_callback_;
|
|
|
|
static Dart_FileReadCallback file_read_callback_;
|
|
|
|
static Dart_FileWriteCallback file_write_callback_;
|
|
|
|
static Dart_FileCloseCallback file_close_callback_;
|
|
|
|
static Dart_EntropySource entropy_source_callback_;
|
2011-10-05 05:20:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dart
|
|
|
|
|
2016-10-26 07:26:03 +00:00
|
|
|
#endif // RUNTIME_VM_DART_H_
|