Skip to content

Commit

Permalink
[vm] Fix isolate reload tests so that they can pass kernel files for …
Browse files Browse the repository at this point in the history
…isolate reload.

Change-Id: I695761a790354eacc0d617cb914d7a4ea2b652aa
Reviewed-on: https://dart-review.googlesource.com/76300
Reviewed-by: Ryan Macnak <rmacnak@google.com>
  • Loading branch information
aam authored and commit-bot@chromium.org committed Sep 26, 2018
1 parent 429bca8 commit cf055d6
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 24 deletions.
23 changes: 22 additions & 1 deletion runtime/vm/isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,28 @@ bool Isolate::ReloadSources(JSONStream* js,
ASSERT(!IsReloading());
SetHasAttemptedReload(true);
reload_context_ = new IsolateReloadContext(this, js);
reload_context_->Reload(force_reload, root_script_url, packages_url);
reload_context_->Reload(force_reload, root_script_url, packages_url,
/* kernel_buffer= */ NULL,
/* kernel_buffer_size= */ 0);
bool success = !reload_context_->reload_aborted();
if (!dont_delete_reload_context) {
DeleteReloadContext();
}
return success;
}

bool Isolate::ReloadKernel(JSONStream* js,
bool force_reload,
const uint8_t* kernel_buffer,
intptr_t kernel_buffer_size,
bool dont_delete_reload_context) {
ASSERT(!IsReloading());
SetHasAttemptedReload(true);
reload_context_ = new IsolateReloadContext(this, js);
reload_context_->Reload(force_reload,
/* root_script_url= */ NULL,
/* packages_url= */ NULL, kernel_buffer,
kernel_buffer_size);
bool success = !reload_context_->reload_aborted();
if (!dont_delete_reload_context) {
DeleteReloadContext();
Expand Down
5 changes: 5 additions & 0 deletions runtime/vm/isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ class Isolate : public BaseIsolate {
const char* root_script_url = NULL,
const char* packages_url = NULL,
bool dont_delete_reload_context = false);
bool ReloadKernel(JSONStream* js,
bool force_reload,
const uint8_t* kernel_buffer = NULL,
intptr_t kernel_buffer_size = 0,
bool dont_delete_reload_context = false);
#endif // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)

const char* MakeRunnable();
Expand Down
35 changes: 22 additions & 13 deletions runtime/vm/isolate_reload.cc
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,12 @@ static void AcceptCompilation(Thread* thread) {
}

// NOTE: This function returns *after* FinalizeLoading is called.
// If [root_script_url] is null, attempt to load from [kernel_buffer].
void IsolateReloadContext::Reload(bool force_reload,
const char* root_script_url,
const char* packages_url_) {
const char* packages_url_,
const uint8_t* kernel_buffer,
intptr_t kernel_buffer_size) {
TIMELINE_SCOPE(Reload);
Thread* thread = Thread::Current();
ASSERT(isolate() == thread->isolate());
Expand Down Expand Up @@ -610,18 +613,25 @@ void IsolateReloadContext::Reload(bool force_reload,
// compiled, so ReadKernelFromFile returns NULL.
kernel_program.set(kernel::Program::ReadFromFile(root_script_url));
if (kernel_program.get() == NULL) {
Dart_SourceFile* modified_scripts = NULL;
intptr_t modified_scripts_count = 0;

FindModifiedSources(thread, force_reload, &modified_scripts,
&modified_scripts_count, packages_url_);

Dart_KernelCompilationResult retval;
{
TransitionVMToNative transition(thread);
retval = KernelIsolate::CompileToKernel(root_lib_url.ToCString(), NULL,
0, modified_scripts_count,
modified_scripts, true, NULL);
if (kernel_buffer != NULL && kernel_buffer_size != 0) {
retval.kernel = const_cast<uint8_t*>(kernel_buffer);
retval.kernel_size = kernel_buffer_size;
retval.status = Dart_KernelCompilationStatus_Ok;
} else {
Dart_SourceFile* modified_scripts = NULL;
intptr_t modified_scripts_count = 0;

FindModifiedSources(thread, force_reload, &modified_scripts,
&modified_scripts_count, packages_url_);

{
TransitionVMToNative transition(thread);
retval = KernelIsolate::CompileToKernel(
root_lib_url.ToCString(), NULL, 0, modified_scripts_count,
modified_scripts, true, NULL);
did_kernel_compilation = true;
}
}

if (retval.status != Dart_KernelCompilationStatus_Ok) {
Expand All @@ -634,7 +644,6 @@ void IsolateReloadContext::Reload(bool force_reload,
CommonFinalizeTail();
return;
}
did_kernel_compilation = true;

// The ownership of the kernel buffer goes now to the VM.
const ExternalTypedData& typed_data = ExternalTypedData::Handle(
Expand Down
4 changes: 3 additions & 1 deletion runtime/vm/isolate_reload.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ class IsolateReloadContext {

void Reload(bool force_reload,
const char* root_script_url = NULL,
const char* packages_url = NULL);
const char* packages_url = NULL,
const uint8_t* kernel_buffer = NULL,
intptr_t kernel_buffer_size = 0);

// All zone allocated objects must be allocated from this zone.
Zone* zone() const { return zone_; }
Expand Down
18 changes: 10 additions & 8 deletions runtime/vm/unit_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ static Dart_Handle IsolateReloadTestLibSource() {
}

static void ReloadTest(Dart_NativeArguments native_args) {
Dart_Handle result = TestCase::TriggerReload();
Dart_Handle result = TestCase::TriggerReload(/* kernel_buffer= */ NULL,
/* kernel_buffer_size= */ 0);
if (Dart_IsError(result)) {
Dart_PropagateError(result);
}
Expand Down Expand Up @@ -610,17 +611,18 @@ Dart_Handle TestCase::SetReloadTestScript(const char* script) {
}
}

Dart_Handle TestCase::TriggerReload() {
Dart_Handle TestCase::TriggerReload(const uint8_t* kernel_buffer,
intptr_t kernel_buffer_size) {
Thread* thread = Thread::Current();
Isolate* isolate = thread->isolate();
JSONStream js;
bool success = false;
{
TransitionNativeToVM transition(thread);
success = isolate->ReloadSources(&js,
false, // force_reload
NULL, NULL,
true); // dont_delete_reload_context
success = isolate->ReloadKernel(&js,
false, // force_reload
kernel_buffer, kernel_buffer_size,
true); // dont_delete_reload_context
OS::PrintErr("RELOAD REPORT:\n%s\n", js.ToCString());
}

Expand Down Expand Up @@ -662,12 +664,12 @@ Dart_Handle TestCase::ReloadTestScript(const char* script) {
SetReloadTestScript(script);
}

return TriggerReload();
return TriggerReload(/* kernel_buffer= */ NULL, /* kernel_buffer_size= */ 0);
}

Dart_Handle TestCase::ReloadTestKernel(const uint8_t* kernel_buffer,
intptr_t kernel_buffer_size) {
return TriggerReload();
return TriggerReload(kernel_buffer, kernel_buffer_size);
}

#endif // !PRODUCT
Expand Down
3 changes: 2 additions & 1 deletion runtime/vm/unit_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ class TestCase : TestCaseBase {
static Dart_Handle SetReloadTestScript(const char* script);

// Initiates the reload.
static Dart_Handle TriggerReload();
static Dart_Handle TriggerReload(const uint8_t* kernel_buffer,
intptr_t kernel_buffer_size);

// Helper function which reloads the current isolate using |script|.
static Dart_Handle ReloadTestScript(const char* script);
Expand Down

0 comments on commit cf055d6

Please sign in to comment.