Make dart:_vmservice a proper builtin library

- Drops custom resource table for sources.
- Stops loading dart:vmservice library by sources.

R=rmacnak@google.com

Review URL: https://codereview.chromium.org/1387043002 .
This commit is contained in:
John McCutchan
2015-10-06 07:58:14 -07:00
parent 0b5fcedaaa
commit af0ab36f7c
22 changed files with 91 additions and 202 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:isolate';
import 'dart:vmservice';
import 'dart:_vmservice';
part 'loader.dart';
part 'resources.dart';
+11 -3
View File
@@ -382,9 +382,17 @@ static RawInstance* CreateLibraryMirror(const Library& lib) {
str = lib.name();
args.SetAt(1, str);
str = lib.url();
if (str.Equals("dart:_builtin") || str.Equals("dart:_blink")) {
// Censored library (grumble).
return Instance::null();
const char* censored_libraries[] = {
"dart:_builtin",
"dart:_blink",
"dart:_vmservice",
NULL,
};
for (intptr_t i = 0; censored_libraries[i] != NULL; i++) {
if (str.Equals(censored_libraries[i])) {
// Censored library (grumble).
return Instance::null();
}
}
if (str.Equals("dart:io")) {
// Hack around dart:io being loaded into non-service isolates in Dartium.
+18
View File
@@ -0,0 +1,18 @@
# Copyright (c) 2015, 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.
# Sources that make up the library "dart:_vmservice".
{
'sources': [
'vmservice/vmservice.dart',
# The above file needs to be first as it imports required libraries.
'vmservice/client.dart',
'vmservice/constants.dart',
'vmservice/running_isolate.dart',
'vmservice/running_isolates.dart',
'vmservice/message.dart',
'vmservice/message_router.dart',
],
}
+4
View File
@@ -75,6 +75,10 @@ static bootstrap_lib_props bootstrap_libraries[] = {
typed_data,
Bootstrap::typed_data_source_paths_,
Bootstrap::typed_data_patch_paths_),
INIT_LIBRARY(ObjectStore::kVMService,
_vmservice,
Bootstrap::vmservice_source_paths_,
NULL),
{ ObjectStore::kNone, NULL, NULL, NULL, NULL }
};
+1
View File
@@ -33,6 +33,7 @@ class Bootstrap : public AllStatic {
static const char* profiler_source_paths_[];
static const char* typed_data_source_paths_[];
static const char* utf_source_paths_[];
static const char* vmservice_source_paths_[];
// Source path mapping for patch URI and 'parts'.
static const char* async_patch_paths_[];
+7
View File
@@ -10,6 +10,7 @@
#include "vm/dart_api_impl.h"
#include "vm/object.h"
#include "vm/object_store.h"
#include "vm/service_isolate.h"
namespace dart {
@@ -129,6 +130,12 @@ void Bootstrap::SetupNativeResolver() {
ASSERT(!library.IsNull());
library.set_native_entry_resolver(resolver);
library.set_native_entry_symbol_resolver(symbol_resolver);
library = Library::VMServiceLibrary();
ASSERT(!library.IsNull());
library.set_native_entry_resolver(
reinterpret_cast<Dart_NativeEntryResolver>(
&ServiceIsolate::NativeResolver));
}
+1 -1
View File
@@ -363,7 +363,7 @@ RawError* Dart::InitializeIsolate(const uint8_t* snapshot_buffer, void* data) {
I->class_table()->Print();
}
ServiceIsolate::MaybeInjectVMServiceLibrary(I);
ServiceIsolate::MaybeMakeServiceIsolate(I);
ServiceIsolate::SendIsolateStartupMessage();
I->debugger()->NotifyIsolateCreated();
+5
View File
@@ -10259,6 +10259,11 @@ RawLibrary* Library::TypedDataLibrary() {
}
RawLibrary* Library::VMServiceLibrary() {
return Isolate::Current()->object_store()->vmservice_library();
}
const char* Library::ToCString() const {
const String& name = String::Handle(url());
return OS::SCreate(Thread::Current()->zone(),
+1
View File
@@ -3491,6 +3491,7 @@ class Library : public Object {
static RawLibrary* NativeWrappersLibrary();
static RawLibrary* ProfilerLibrary();
static RawLibrary* TypedDataLibrary();
static RawLibrary* VMServiceLibrary();
// Eagerly compile all classes and functions in the library.
static RawError* CompileAll();
+1
View File
@@ -71,6 +71,7 @@ ObjectStore::ObjectStore()
profiler_library_(Library::null()),
root_library_(Library::null()),
typed_data_library_(Library::null()),
vmservice_library_(Library::null()),
libraries_(GrowableObjectArray::null()),
pending_classes_(GrowableObjectArray::null()),
pending_functions_(GrowableObjectArray::null()),
+6
View File
@@ -32,6 +32,7 @@ class ObjectStore {
kMirrors,
kProfiler,
kTypedData,
kVMService,
};
~ObjectStore();
@@ -265,6 +266,7 @@ class ObjectStore {
RawLibrary* mirrors_library() const { return mirrors_library_; }
RawLibrary* profiler_library() const { return profiler_library_; }
RawLibrary* typed_data_library() const { return typed_data_library_; }
RawLibrary* vmservice_library() const { return vmservice_library_; }
void set_bootstrap_library(BootstrapLibraryId index, const Library& value) {
switch (index) {
@@ -301,6 +303,9 @@ class ObjectStore {
case kTypedData:
typed_data_library_ = value.raw();
break;
case kVMService:
vmservice_library_ = value.raw();
break;
default:
UNREACHABLE();
}
@@ -520,6 +525,7 @@ class ObjectStore {
RawLibrary* profiler_library_;
RawLibrary* root_library_;
RawLibrary* typed_data_library_;
RawLibrary* vmservice_library_;
RawGrowableObjectArray* libraries_;
RawGrowableObjectArray* pending_classes_;
RawGrowableObjectArray* pending_functions_;
+4 -165
View File
@@ -31,80 +31,6 @@ DEFINE_FLAG(bool, trace_service, false, "Trace VM service requests.");
DEFINE_FLAG(bool, trace_service_pause_events, false,
"Trace VM service isolate pause events.");
struct ResourcesEntry {
const char* path_;
const char* resource_;
int length_;
};
extern ResourcesEntry __service_resources_[];
class Resources {
public:
static const int kNoSuchInstance = -1;
static int ResourceLookup(const char* path, const char** resource) {
ResourcesEntry* table = ResourceTable();
for (int i = 0; table[i].path_ != NULL; i++) {
const ResourcesEntry& entry = table[i];
if (strcmp(path, entry.path_) == 0) {
*resource = entry.resource_;
ASSERT(entry.length_ > 0);
return entry.length_;
}
}
return kNoSuchInstance;
}
static const char* Path(int idx) {
ASSERT(idx >= 0);
ResourcesEntry* entry = At(idx);
if (entry == NULL) {
return NULL;
}
ASSERT(entry->path_ != NULL);
return entry->path_;
}
static int Length(int idx) {
ASSERT(idx >= 0);
ResourcesEntry* entry = At(idx);
if (entry == NULL) {
return kNoSuchInstance;
}
ASSERT(entry->path_ != NULL);
return entry->length_;
}
static const uint8_t* Resource(int idx) {
ASSERT(idx >= 0);
ResourcesEntry* entry = At(idx);
if (entry == NULL) {
return NULL;
}
return reinterpret_cast<const uint8_t*>(entry->resource_);
}
private:
static ResourcesEntry* At(int idx) {
ASSERT(idx >= 0);
ResourcesEntry* table = ResourceTable();
for (int i = 0; table[i].path_ != NULL; i++) {
if (idx == i) {
return &table[i];
}
}
return NULL;
}
static ResourcesEntry* ResourceTable() {
return &__service_resources_[0];
}
DISALLOW_ALLOCATION();
DISALLOW_IMPLICIT_CONSTRUCTORS(Resources);
};
static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
return reinterpret_cast<uint8_t*>(new_ptr);
@@ -350,9 +276,9 @@ static ServiceNativeEntry _ServiceNativeEntries[] = {
};
static Dart_NativeFunction ServiceNativeResolver(Dart_Handle name,
int num_arguments,
bool* auto_setup_scope) {
Dart_NativeFunction ServiceIsolate::NativeResolver(Dart_Handle name,
int num_arguments,
bool* auto_setup_scope) {
const Object& obj = Object::Handle(Api::UnwrapHandle(name));
if (!obj.IsString()) {
return NULL;
@@ -529,7 +455,7 @@ void ServiceIsolate::SetLoadPort(Dart_Port port) {
}
void ServiceIsolate::MaybeInjectVMServiceLibrary(Isolate* I) {
void ServiceIsolate::MaybeMakeServiceIsolate(Isolate* I) {
Thread* T = Thread::Current();
ASSERT(I == T->isolate());
ASSERT(I != NULL);
@@ -543,46 +469,6 @@ void ServiceIsolate::MaybeInjectVMServiceLibrary(Isolate* I) {
return;
}
SetServiceIsolate(I);
StackZone zone(T);
HANDLESCOPE(T);
// Register dart:vmservice library.
const String& url_str = String::Handle(Z, Symbols::DartVMService().raw());
const Library& library = Library::Handle(Z, Library::New(url_str));
library.Register();
library.set_native_entry_resolver(ServiceNativeResolver);
// Temporarily install our library tag handler.
I->set_library_tag_handler(LibraryTagHandler);
// Get script source.
const char* resource = NULL;
const char* path = "/vmservice.dart";
intptr_t r = Resources::ResourceLookup(path, &resource);
ASSERT(r != Resources::kNoSuchInstance);
ASSERT(resource != NULL);
const String& source_str = String::Handle(Z,
String::FromUTF8(reinterpret_cast<const uint8_t*>(resource), r));
ASSERT(!source_str.IsNull());
const Script& script = Script::Handle(Z,
Script::New(url_str, source_str, RawScript::kLibraryTag));
// Compile script.
Dart_EnterScope(); // Need to enter scope for tag handler.
library.SetLoadInProgress();
const Error& error = Error::Handle(Z, Compiler::Compile(library, script));
if (!error.IsNull()) {
OS::PrintErr("vm-service: Isolate creation error: %s\n",
error.ToErrorCString());
}
ASSERT(error.IsNull());
Dart_Handle result = Dart_FinalizeLoading(false);
ASSERT(!Dart_IsError(result));
Dart_ExitScope();
// Uninstall our library tag handler.
I->set_library_tag_handler(NULL);
}
@@ -804,51 +690,4 @@ void ServiceIsolate::Shutdown() {
}
}
Dart_Handle ServiceIsolate::GetSource(const char* name) {
ASSERT(name != NULL);
int i = 0;
while (true) {
const char* path = Resources::Path(i);
if (path == NULL) {
break;
}
ASSERT(*path != '\0');
// Skip the '/'.
path++;
if (strcmp(name, path) == 0) {
const uint8_t* str = Resources::Resource(i);
intptr_t length = Resources::Length(i);
return Dart_NewStringFromUTF8(str, length);
}
i++;
}
FATAL1("vm-service: Could not find embedded source file: %s ", name);
return Dart_Null();
}
Dart_Handle ServiceIsolate::LibraryTagHandler(Dart_LibraryTag tag,
Dart_Handle library,
Dart_Handle url) {
if (tag == Dart_kCanonicalizeUrl) {
// url is already canonicalized.
return url;
}
if (tag != Dart_kSourceTag) {
FATAL("ServiceIsolate::LibraryTagHandler encountered an unexpected tag.");
}
ASSERT(tag == Dart_kSourceTag);
const char* url_string = NULL;
Dart_Handle result = Dart_StringToCString(url, &url_string);
if (Dart_IsError(result)) {
return result;
}
Dart_Handle source = GetSource(url_string);
if (Dart_IsError(source)) {
return source;
}
return Dart_LoadSource(library, url, source, 0, 0);
}
} // namespace dart
+5 -4
View File
@@ -42,14 +42,14 @@ class ServiceIsolate : public AllStatic {
static void ConstructExitMessageAndCache(Isolate* isolate);
static void FinishedExiting();
static void FinishedInitializing();
static void MaybeInjectVMServiceLibrary(Isolate* isolate);
static void MaybeMakeServiceIsolate(Isolate* isolate);
static Dart_IsolateCreateCallback create_callback() {
return create_callback_;
}
static Dart_Handle GetSource(const char* name);
static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, Dart_Handle library,
Dart_Handle url);
static Dart_NativeFunction NativeResolver(Dart_Handle name,
int num_arguments,
bool* auto_setup_scope);
static Dart_IsolateCreateCallback create_callback_;
static uint8_t* exit_message_;
@@ -65,6 +65,7 @@ class ServiceIsolate : public AllStatic {
friend class Dart;
friend class RunServiceTask;
friend class ServiceIsolateNatives;
friend class Bootstrap;
};
} // namespace dart
+1 -1
View File
@@ -343,7 +343,7 @@ class ObjectPointerVisitor;
V(DartIsolate, "dart:isolate") \
V(DartMirrors, "dart:mirrors") \
V(DartTypedData, "dart:typed_data") \
V(DartVMService, "dart:vmservice") \
V(DartVMService, "dart:_vmservice") \
V(DartIOLibName, "dart.io") \
V(EvalSourceUri, "evaluate:source") \
V(_Random, "_Random") \
+25 -27
View File
@@ -26,30 +26,23 @@
'mirrors_cc_file': '<(gen_source_dir)/mirrors_gen.cc',
'mirrors_patch_cc_file': '<(gen_source_dir)/mirrors_patch_gen.cc',
'profiler_cc_file': '<(gen_source_dir)/profiler_gen.cc',
'service_cc_file': '<(gen_source_dir)/service_gen.cc',
'snapshot_test_dat_file': '<(gen_source_dir)/snapshot_test.dat',
'snapshot_test_in_dat_file': 'snapshot_test_in.dat',
'snapshot_test_dart_file': 'snapshot_test.dart',
'typed_data_cc_file': '<(gen_source_dir)/typed_data_gen.cc',
'typed_data_patch_cc_file': '<(gen_source_dir)/typed_data_patch_gen.cc',
'vmservice_cc_file': '<(gen_source_dir)/vmservice_gen.cc',
},
'targets': [
{
'target_name': 'libdart_vm',
'type': 'static_library',
'toolsets':['host', 'target'],
'dependencies': [
'generate_service_cc_file#host'
],
'includes': [
'vm_sources.gypi',
'../platform/platform_headers.gypi',
'../platform/platform_sources.gypi',
],
'sources': [
# Include generated source files.
'<(service_cc_file)',
],
'sources/': [
# Exclude all _test.[cc|h] files.
['exclude', '_test\\.(cc|h)$'],
@@ -105,18 +98,11 @@
'target_name': 'libdart_vm_nosnapshot',
'type': 'static_library',
'toolsets':['host', 'target'],
'dependencies': [
'generate_service_cc_file#host'
],
'includes': [
'vm_sources.gypi',
'../platform/platform_headers.gypi',
'../platform/platform_sources.gypi',
],
'sources': [
# Include generated source files.
'<(service_cc_file)',
],
'sources/': [
# Exclude all _test.[cc|h] files.
['exclude', '_test\\.(cc|h)$'],
@@ -197,6 +183,7 @@
'generate_profiler_cc_file#host',
'generate_typed_data_cc_file#host',
'generate_typed_data_patch_cc_file#host',
'generate_vmservice_cc_file#host',
],
'includes': [
'../lib/async_sources.gypi',
@@ -233,6 +220,7 @@
'<(profiler_cc_file)',
'<(typed_data_cc_file)',
'<(typed_data_patch_cc_file)',
'<(vmservice_cc_file)',
],
'include_dirs': [
'..',
@@ -252,6 +240,7 @@
'../lib/math_sources.gypi',
'../lib/mirrors_sources.gypi',
'../lib/typed_data_sources.gypi',
'../lib/vmservice_sources.gypi',
],
'sources': [
'bootstrap_nocore.cc',
@@ -1128,32 +1117,41 @@
]
},
{
'target_name': 'generate_service_cc_file',
'target_name': 'generate_vmservice_cc_file',
'type': 'none',
'toolsets':['host'],
'includes': [
'service_sources.gypi',
'../lib/vmservice_sources.gypi',
],
'sources/': [
# Exclude all .[cc|h] files.
# This is only here for reference. Excludes happen after
# variable expansion, so the script has to do its own
# exclude processing of the sources being passed.
['exclude', '\\.cc|h$'],
],
'actions': [
{
'action_name': 'generate_service_cc',
'action_name': 'generate_vmservice_cc',
'inputs': [
'../tools/create_resources.py',
'../tools/gen_library_src_paths.py',
'<(libgen_in_cc_file)',
'<@(_sources)',
],
'outputs': [
'<(service_cc_file)',
'<(vmservice_cc_file)',
],
'action': [
'python',
'tools/create_resources.py',
'--output', '<(service_cc_file)',
'--outer_namespace', 'dart',
'--table_name', 'service',
'--root_prefix', 'vm/service/',
'<@(_sources)'
'tools/gen_library_src_paths.py',
'--output', '<(vmservice_cc_file)',
'--input_cc', '<(libgen_in_cc_file)',
'--include', 'vm/bootstrap.h',
'--var_name', 'dart::Bootstrap::vmservice_source_paths_',
'--library_name', 'dart:_vmservice',
'<@(_sources)',
],
'message': 'Generating ''<(service_cc_file)'' file.'
'message': 'Generating ''<(vmservice_cc_file)'' file.'
},
]
},