Skip to content

Commit d0139e8

Browse files
a-sivacommit-bot@chromium.org
authored andcommitted
[VM] More cleanup in the loader code
- Removed ResolveDependenciesAsFilePaths functionality as the loader does not track any dependencies (this is now provided by the kernel isolate) - Removed ResolveAsFilePath functionality from the loader class - Removed some left over code related to deferred loading Change-Id: Ic1b1a79b07020bb7082e9efb7544b73931290faf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122220 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Siva Annamalai <asiva@google.com>
1 parent 73dd5f7 commit d0139e8

File tree

6 files changed

+19
-224
lines changed

6 files changed

+19
-224
lines changed

runtime/bin/isolate_data.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ IsolateGroupData::IsolateGroupData(const char* url,
1717
: script_url((url != NULL) ? strdup(url) : NULL),
1818
package_root(NULL),
1919
app_snapshot_(app_snapshot),
20-
dependencies_(NULL),
2120
resolved_packages_config_(NULL),
2221
kernel_buffer_(NULL),
2322
kernel_buffer_size_(0),
@@ -41,7 +40,6 @@ IsolateGroupData::~IsolateGroupData() {
4140
resolved_packages_config_ = NULL;
4241
kernel_buffer_ = NULL;
4342
kernel_buffer_size_ = 0;
44-
delete dependencies_;
4543
}
4644

4745
IsolateData::IsolateData(IsolateGroupData* isolate_group_data)

runtime/bin/isolate_data.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ class IsolateGroupData {
8888
resolved_packages_config_ = strdup(packages_config);
8989
}
9090

91-
MallocGrowableArray<char*>* dependencies() const { return dependencies_; }
92-
void set_dependencies(MallocGrowableArray<char*>* deps) {
93-
dependencies_ = deps;
94-
}
95-
9691
bool RunFromAppSnapshot() const {
9792
// If the main isolate is using an app snapshot the [app_snapshot_] pointer
9893
// will be still nullptr (see main.cc:CreateIsolateGroupAndSetupHelper)
@@ -106,7 +101,6 @@ class IsolateGroupData {
106101
friend class IsolateData; // For packages_file_
107102

108103
std::unique_ptr<AppSnapshot> app_snapshot_;
109-
MallocGrowableArray<char*>* dependencies_;
110104
char* resolved_packages_config_;
111105
std::shared_ptr<uint8_t> kernel_buffer_;
112106
intptr_t kernel_buffer_size_;

runtime/bin/loader.cc

Lines changed: 19 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ extern DFE dfe;
2828
// Keep in sync with loader.dart.
2929
static const intptr_t _Dart_kInitLoader = 4;
3030
static const intptr_t _Dart_kImportExtension = 9;
31-
static const intptr_t _Dart_kResolveAsFilePath = 10;
3231

3332
Loader::Loader(IsolateData* isolate_data)
3433
: port_(ILLEGAL_PORT),
@@ -259,46 +258,6 @@ static bool PathContainsSeparator(const char* path) {
259258
(strstr(path, File::PathSeparator()) != NULL));
260259
}
261260

262-
void Loader::AddDependencyLocked(Loader* loader, const char* resolved_uri) {
263-
MallocGrowableArray<char*>* dependencies =
264-
loader->isolate_group_data()->dependencies();
265-
if (dependencies == NULL) {
266-
return;
267-
}
268-
dependencies->Add(strdup(resolved_uri));
269-
}
270-
271-
void Loader::ResolveDependenciesAsFilePaths() {
272-
IsolateGroupData* isolate_group_data =
273-
reinterpret_cast<IsolateGroupData*>(Dart_CurrentIsolateGroupData());
274-
ASSERT(isolate_group_data != NULL);
275-
MallocGrowableArray<char*>* dependencies = isolate_group_data->dependencies();
276-
if (dependencies == NULL) {
277-
return;
278-
}
279-
280-
for (intptr_t i = 0; i < dependencies->length(); i++) {
281-
char* resolved_uri = (*dependencies)[i];
282-
283-
uint8_t* file_path = NULL;
284-
intptr_t file_path_length = -1;
285-
Dart_Handle uri = Dart_NewStringFromCString(resolved_uri);
286-
ASSERT(!Dart_IsError(uri));
287-
Dart_Handle result =
288-
Loader::ResolveAsFilePath(uri, &file_path, &file_path_length);
289-
if (Dart_IsError(result)) {
290-
Syslog::Print("Error resolving dependency: %s\n", Dart_GetError(result));
291-
return;
292-
}
293-
294-
// Convert buffer buffer to NUL-terminated string.
295-
(*dependencies)[i] = Utils::StrNDup(
296-
reinterpret_cast<const char*>(file_path), file_path_length);
297-
free(file_path);
298-
free(resolved_uri);
299-
}
300-
}
301-
302261
class ScopedDecompress : public ValueObject {
303262
public:
304263
ScopedDecompress(const uint8_t** payload, intptr_t* payload_length)
@@ -343,17 +302,14 @@ bool Loader::ProcessResultLocked(Loader* loader, Loader::IOResult* result) {
343302
Dart_NewStringFromCString(reinterpret_cast<char*>(result->library_uri));
344303
}
345304

346-
AddDependencyLocked(loader, result->resolved_uri);
347-
348305
// A negative result tag indicates a loading error occurred in the service
349306
// isolate. The payload is a C string of the error message.
350307
if (result->tag < 0) {
351308
Dart_Handle library = Dart_LookupLibrary(uri);
352309
Dart_Handle error =
353310
Dart_NewStringFromUTF8(result->payload, result->payload_length);
354311
// If a library with the given uri exists, give it a chance to handle
355-
// the error. If the load requests stems from a deferred library load,
356-
// an IO error is not fatal.
312+
// the error.
357313
if (LibraryHandleError(library, error)) {
358314
return true;
359315
}
@@ -421,23 +377,6 @@ bool Loader::ProcessResultLocked(Loader* loader, Loader::IOResult* result) {
421377
return false;
422378
}
423379

424-
bool Loader::ProcessPayloadResultLocked(Loader* loader,
425-
Loader::IOResult* result) {
426-
// A negative result tag indicates a loading error occurred in the service
427-
// isolate. The payload is a C string of the error message.
428-
if (result->tag < 0) {
429-
Dart_Handle error =
430-
Dart_NewStringFromUTF8(result->payload, result->payload_length);
431-
loader->error_ = Dart_NewUnhandledExceptionError(error);
432-
return false;
433-
}
434-
loader->payload_length_ = result->payload_length;
435-
loader->payload_ =
436-
reinterpret_cast<uint8_t*>(::malloc(loader->payload_length_));
437-
memmove(loader->payload_, result->payload, loader->payload_length_);
438-
return true;
439-
}
440-
441380
bool Loader::ProcessQueueLocked(ProcessResult process_result) {
442381
bool hit_error = false;
443382
for (intptr_t i = 0; i < results_length(); i++) {
@@ -510,53 +449,6 @@ Dart_Handle Loader::ReloadNativeExtensions() {
510449
return Dart_True();
511450
}
512451

513-
Dart_Handle Loader::SendAndProcessReply(intptr_t tag,
514-
Dart_Handle url,
515-
uint8_t** payload,
516-
intptr_t* payload_length) {
517-
auto isolate_data = reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData());
518-
ASSERT(isolate_data != NULL);
519-
ASSERT(!isolate_data->HasLoader());
520-
Loader* loader = NULL;
521-
522-
// Setup the loader. The constructor does a bunch of leg work.
523-
loader = new Loader(isolate_data);
524-
loader->Init(isolate_data->isolate_group_data()->package_root,
525-
isolate_data->packages_file(),
526-
DartUtils::original_working_directory, NULL);
527-
ASSERT(loader != NULL);
528-
ASSERT(isolate_data->HasLoader());
529-
530-
// Now send a load request to the service isolate.
531-
loader->SendRequest(tag, url, Dart_Null());
532-
533-
// Wait for a reply to the load request.
534-
loader->BlockUntilComplete(ProcessPayloadResultLocked);
535-
536-
// Copy fields from the loader before deleting it.
537-
// The payload array itself which was malloced above is freed by
538-
// the caller of LoadUrlContents.
539-
Dart_Handle error = loader->error();
540-
*payload = loader->payload_;
541-
*payload_length = loader->payload_length_;
542-
543-
// Destroy the loader. The destructor does a bunch of leg work.
544-
delete loader;
545-
546-
// An error occurred during loading.
547-
if (!Dart_IsNull(error)) {
548-
return error;
549-
}
550-
return Dart_Null();
551-
}
552-
553-
Dart_Handle Loader::ResolveAsFilePath(Dart_Handle url,
554-
uint8_t** payload,
555-
intptr_t* payload_length) {
556-
return SendAndProcessReply(_Dart_kResolveAsFilePath, url, payload,
557-
payload_length);
558-
}
559-
560452
IsolateGroupData* Loader::isolate_group_data() {
561453
return isolate_data_->isolate_group_data();
562454
}
@@ -662,13 +554,6 @@ Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag,
662554
// Grab this isolate's loader.
663555
Loader* loader = NULL;
664556

665-
// The outer invocation of the tag handler for this isolate. We make the outer
666-
// invocation block and allow any nested invocations to operate in parallel.
667-
const bool blocking_call = !isolate_data->HasLoader();
668-
669-
// If we are the outer invocation of the tag handler and the tag is an import
670-
// this means that we are starting a deferred library load.
671-
const bool is_deferred_import = blocking_call && (tag == Dart_kImportTag);
672557
if (!isolate_data->HasLoader()) {
673558
// The isolate doesn't have a loader -- this is the outer invocation which
674559
// will block.
@@ -717,42 +602,25 @@ Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag,
717602
}
718603
}
719604

720-
if (blocking_call) {
721-
// The outer invocation of the tag handler will block here until all nested
722-
// invocations complete.
723-
loader->BlockUntilComplete(ProcessResultLocked);
724-
725-
// Remember the error (if any).
726-
Dart_Handle error = loader->error();
727-
// Destroy the loader. The destructor does a bunch of leg work.
728-
delete loader;
729-
730-
// An error occurred during loading.
731-
if (!Dart_IsNull(error)) {
732-
if (false && is_deferred_import) {
733-
// This blocks handles transitive load errors caused by a deferred
734-
// import. Non-transitive load errors are handled above (see callers of
735-
// |LibraryHandleError|). To handle the transitive case, we give the
736-
// originating deferred library an opportunity to handle it.
737-
Dart_Handle deferred_library = Dart_LookupLibrary(url);
738-
if (!LibraryHandleError(deferred_library, error)) {
739-
// Library did not handle it, return to caller as an unhandled
740-
// exception.
741-
return Dart_NewUnhandledExceptionError(error);
742-
}
743-
} else {
744-
// We got an error during loading but we aren't loading a deferred
745-
// library, return the error to the caller.
746-
return error;
747-
}
748-
}
605+
// The outer invocation of the tag handler will block here until all nested
606+
// invocations complete.
607+
loader->BlockUntilComplete(ProcessResultLocked);
749608

750-
// Finalize loading. This will complete any futures for completed deferred
751-
// loads.
752-
error = Dart_FinalizeLoading(true);
753-
if (Dart_IsError(error)) {
754-
return error;
755-
}
609+
// Remember the error (if any).
610+
Dart_Handle error = loader->error();
611+
// Destroy the loader. The destructor does a bunch of leg work.
612+
delete loader;
613+
614+
// An error occurred during loading.
615+
if (!Dart_IsNull(error)) {
616+
// We got an error during loading, return the error to the caller.
617+
return error;
618+
}
619+
620+
// Finalize loading.
621+
error = Dart_FinalizeLoading(true);
622+
if (Dart_IsError(error)) {
623+
return error;
756624
}
757625
return Dart_Null();
758626
}

runtime/bin/loader.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ class Loader {
2525

2626
static Dart_Handle ReloadNativeExtensions();
2727

28-
static void ResolveDependenciesAsFilePaths();
29-
3028
// A static tag handler that hides all usage of a loader for an isolate.
3129
static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag,
3230
Dart_Handle library,
@@ -90,30 +88,15 @@ class Loader {
9088
// Send a request from the tag handler to the service isolate.
9189
void SendRequest(intptr_t tag, Dart_Handle url, Dart_Handle library_url);
9290

93-
static Dart_Handle SendAndProcessReply(intptr_t tag,
94-
Dart_Handle url,
95-
uint8_t** payload,
96-
intptr_t* payload_length);
97-
98-
static Dart_Handle ResolveAsFilePath(Dart_Handle url,
99-
uint8_t** payload,
100-
intptr_t* payload_length);
101-
10291
/// Queue |message| and notify the loader that a message is available.
10392
void QueueMessage(Dart_CObject* message);
10493

10594
/// Blocks the caller until the loader is finished.
10695
void BlockUntilComplete(ProcessResult process_result);
10796

108-
/// Saves a script dependency when applicable.
109-
static void AddDependencyLocked(Loader* loader, const char* resolved_uri);
110-
11197
/// Returns false if |result| is an error and the loader should quit.
11298
static bool ProcessResultLocked(Loader* loader, IOResult* result);
11399

114-
/// Returns false if |result| is an error and the loader should quit.
115-
static bool ProcessPayloadResultLocked(Loader* loader, IOResult* result);
116-
117100
/// Returns false if an error occurred and the loader should quit.
118101
bool ProcessQueueLocked(ProcessResult process_result);
119102

runtime/bin/main.cc

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,6 @@ static void WriteDepsFile(Dart_Isolate isolate) {
131131
if (Options::depfile() == NULL) {
132132
return;
133133
}
134-
Loader::ResolveDependenciesAsFilePaths();
135-
auto isolate_group_data =
136-
reinterpret_cast<IsolateGroupData*>(Dart_IsolateGroupData(isolate));
137-
ASSERT(isolate_group_data != NULL);
138-
MallocGrowableArray<char*>* dependencies = isolate_group_data->dependencies();
139-
ASSERT(dependencies != NULL);
140134
File* file =
141135
File::Open(NULL, Options::depfile(), File::kWriteTruncate);
142136
if (file == NULL) {
@@ -149,11 +143,6 @@ static void WriteDepsFile(Dart_Isolate isolate) {
149143
} else {
150144
success &= file->Print("%s: ", Options::depfile_output_filename());
151145
}
152-
for (intptr_t i = 0; i < dependencies->length(); i++) {
153-
char* dep = dependencies->At(i);
154-
success &= file->Print("%s ", dep);
155-
free(dep);
156-
}
157146
if (kernel_isolate_is_running) {
158147
Dart_KernelCompilationResult result = Dart_KernelListDependencies();
159148
if (result.status != Dart_KernelCompilationStatus_Ok) {
@@ -171,7 +160,6 @@ static void WriteDepsFile(Dart_Isolate isolate) {
171160
Options::depfile());
172161
}
173162
file->Release();
174-
dependencies->Clear();
175163
}
176164

177165
static void OnExitHook(int64_t exit_code) {
@@ -682,9 +670,6 @@ static Dart_Isolate CreateIsolateGroupAndSetupHelper(
682670
kernel_buffer_size);
683671
}
684672
}
685-
if (is_main_isolate && (Options::depfile() != NULL)) {
686-
isolate_group_data->set_dependencies(new MallocGrowableArray<char*>());
687-
}
688673

689674
Dart_Isolate isolate = NULL;
690675

runtime/bin/vmservice/loader.dart

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,6 @@ const _Dart_kResolvePackageUri = 8; // Resolve a package: uri.
962962

963963
// Extra requests. Keep these in sync between loader.dart and loader.cc.
964964
const _Dart_kImportExtension = 9; // Import a dart-ext: file.
965-
const _Dart_kResolveAsFilePath = 10; // Resolve uri to file path.
966965

967966
// External entry point for loader requests.
968967
_processLoadRequest(request) {
@@ -1091,38 +1090,6 @@ _processLoadRequest(request) {
10911090
break;
10921091
}
10931092
break;
1094-
case _Dart_kResolveAsFilePath:
1095-
loaderState._triggerPackageResolution(() {
1096-
String uri = request[4];
1097-
Uri resolvedUri = Uri.parse(_sanitizeWindowsPath(uri));
1098-
try {
1099-
if (resolvedUri.scheme == 'package') {
1100-
resolvedUri = loaderState._resolvePackageUri(resolvedUri);
1101-
}
1102-
if (resolvedUri.scheme == '' || resolvedUri.scheme == 'file') {
1103-
resolvedUri = loaderState._workingDirectory.resolveUri(resolvedUri);
1104-
var msg = new List(5);
1105-
msg[0] = tag;
1106-
msg[1] = uri;
1107-
msg[2] = resolvedUri.toString();
1108-
msg[3] = null;
1109-
msg[4] = resolvedUri.toFilePath();
1110-
sp.send(msg);
1111-
} else {
1112-
throw "Cannot resolve scheme (${resolvedUri.scheme}) to file path"
1113-
" for $resolvedUri";
1114-
}
1115-
} catch (e) {
1116-
var msg = new List(5);
1117-
msg[0] = -tag;
1118-
msg[1] = uri;
1119-
msg[2] = resolvedUri.toString();
1120-
msg[3] = null;
1121-
msg[4] = e.toString();
1122-
sp.send(msg);
1123-
}
1124-
});
1125-
break;
11261093
default:
11271094
_log('Unknown loader request tag=$tag from $isolateId');
11281095
}

0 commit comments

Comments
 (0)