1// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_VM_KERNEL_ISOLATE_H_
6#define RUNTIME_VM_KERNEL_ISOLATE_H_
7
8#include <vector>
9
10#include "include/dart_api.h"
11#include "include/dart_native_api.h"
12
13#include "vm/allocation.h"
14#include "vm/dart.h"
15#include "vm/os_thread.h"
16
17namespace dart {
18
19// TODO(33433): The kernel service does not belong in the VM.
20
21class KernelIsolate : public AllStatic {
22#if !defined(DART_PRECOMPILED_RUNTIME)
23
24 public:
25 static const char* kName;
26 static const int kCompileTag;
27 static const int kUpdateSourcesTag;
28 static const int kAcceptTag;
29 static const int kTrainTag;
30 static const int kCompileExpressionTag;
31 static const int kListDependenciesTag;
32 static const int kNotifyIsolateShutdown;
33 static const int kDetectNullabilityTag;
34
35 static void InitializeState();
36 static bool Start();
37 static void Shutdown();
38
39 static bool NameEquals(const char* name);
40 static bool Exists();
41 static bool IsRunning();
42 static bool IsKernelIsolate(const Isolate* isolate);
43 static Dart_Port WaitForKernelPort();
44 static Dart_Port KernelPort() { return kernel_port_; }
45
46 static Dart_KernelCompilationResult CompileToKernel(
47 const char* script_uri,
48 const uint8_t* platform_kernel,
49 intptr_t platform_kernel_size,
50 int source_files_count = 0,
51 Dart_SourceFile source_files[] = NULL,
52 bool incremental_compile = true,
53 const char* package_config = NULL,
54 const char* multiroot_filepaths = NULL,
55 const char* multiroot_scheme = NULL);
56
57 static bool DetectNullSafety(const char* script_uri,
58 const char* package_config,
59 const char* original_working_directory);
60
61 static Dart_KernelCompilationResult AcceptCompilation();
62 static Dart_KernelCompilationResult UpdateInMemorySources(
63 int source_files_count,
64 Dart_SourceFile source_files[]);
65
66 static Dart_KernelCompilationResult CompileExpressionToKernel(
67 const uint8_t* platform_kernel,
68 intptr_t platform_kernel_size,
69 const char* expression,
70 const Array& definitions,
71 const Array& type_definitions,
72 const char* library_url,
73 const char* klass,
74 bool is_static);
75
76 static Dart_KernelCompilationResult ListDependencies();
77
78 static void NotifyAboutIsolateShutdown(const Isolate* isolate);
79
80 static void AddExperimentalFlag(const char* value);
81 static bool GetExperimentalFlag(const char* value);
82
83 protected:
84 static void InitCallback(Isolate* I);
85 static void SetKernelIsolate(Isolate* isolate);
86 static void SetLoadPort(Dart_Port port);
87 static void FinishedExiting();
88 static void FinishedInitializing();
89 static void InitializingFailed();
90 static Dart_IsolateGroupCreateCallback create_group_callback() {
91 return create_group_callback_;
92 }
93
94 static Dart_IsolateGroupCreateCallback create_group_callback_;
95 static Monitor* monitor_;
96 enum State {
97 kNotStarted,
98 kStopped,
99 kStarting,
100 kStarted,
101 kStopping,
102 };
103 static State state_;
104 static Isolate* isolate_;
105 static Dart_Port kernel_port_;
106
107 static MallocGrowableArray<char*>* experimental_flags_;
108#else
109
110 public:
111 static bool IsRunning() { return false; }
112 static void Shutdown() {}
113 static bool IsKernelIsolate(const Isolate* isolate) { return false; }
114 static void NotifyAboutIsolateShutdown(const Isolate* isolate) {}
115 static bool GetExperimentalFlag(const char* value) { return false; }
116
117 protected:
118 static void SetKernelIsolate(Isolate* isolate) { UNREACHABLE(); }
119
120#endif // !defined(DART_PRECOMPILED_RUNTIME)
121
122 friend class Dart;
123 friend class Isolate;
124 friend class RunKernelTask;
125};
126
127} // namespace dart
128
129#endif // RUNTIME_VM_KERNEL_ISOLATE_H_
130