Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: runtime/bin/loader.cc

Issue 2991393002: [standalone] Automatically decompress gzip'd resources, including sources and script snapshots. (Closed)
Patch Set: Fix case in decompression where the snapshot it smaller than the chunk size. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/gzip.cc ('k') | runtime/bin/main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "bin/loader.h" 5 #include "bin/loader.h"
6 6
7 #include "bin/builtin.h" 7 #include "bin/builtin.h"
8 #include "bin/dartutils.h" 8 #include "bin/dartutils.h"
9 #include "bin/dfe.h" 9 #include "bin/dfe.h"
10 #include "bin/extensions.h" 10 #include "bin/extensions.h"
11 #include "bin/file.h" 11 #include "bin/file.h"
12 #include "bin/gzip.h"
12 #include "bin/lockers.h" 13 #include "bin/lockers.h"
13 #include "bin/utils.h" 14 #include "bin/utils.h"
14 #include "include/dart_tools_api.h" 15 #include "include/dart_tools_api.h"
15 #include "platform/growable_array.h" 16 #include "platform/growable_array.h"
16 17
17 namespace dart { 18 namespace dart {
18 namespace bin { 19 namespace bin {
19 20
20 // Development flag. 21 // Development flag.
21 static bool trace_loader = false; 22 static bool trace_loader = false;
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 return; 312 return;
312 } 313 }
313 314
314 (*dependencies)[i] = 315 (*dependencies)[i] =
315 StringUtils::StrNDup(reinterpret_cast<const char*>(scoped_file_path), 316 StringUtils::StrNDup(reinterpret_cast<const char*>(scoped_file_path),
316 scoped_file_path_length); 317 scoped_file_path_length);
317 free(resolved_uri); 318 free(resolved_uri);
318 } 319 }
319 } 320 }
320 321
322 class ScopedDecompress : public ValueObject {
323 public:
324 ScopedDecompress(const uint8_t** payload, intptr_t* payload_length)
325 : payload_(payload),
326 payload_length_(payload_length),
327 decompressed_(NULL) {
328 DartUtils::MagicNumber payload_type =
329 DartUtils::SniffForMagicNumber(*payload, *payload_length);
330 if (payload_type == DartUtils::kGzipMagicNumber) {
331 int64_t start = Dart_TimelineGetMicros();
332 intptr_t decompressed_length = 0;
333 Decompress(*payload, *payload_length, &decompressed_,
334 &decompressed_length);
335 int64_t end = Dart_TimelineGetMicros();
336 Dart_TimelineEvent("Decompress", start, end, Dart_Timeline_Event_Duration,
337 0, NULL, NULL);
338 *payload_ = decompressed_;
339 *payload_length_ = decompressed_length;
340 }
341 }
342
343 ~ScopedDecompress() {
344 if (decompressed_ != NULL) {
345 free(decompressed_);
346 }
347 }
348
349 private:
350 const uint8_t** payload_;
351 intptr_t* payload_length_;
352 uint8_t* decompressed_;
353 };
354
321 bool Loader::ProcessResultLocked(Loader* loader, Loader::IOResult* result) { 355 bool Loader::ProcessResultLocked(Loader* loader, Loader::IOResult* result) {
322 // We have to copy everything we care about out of |result| because after 356 // We have to copy everything we care about out of |result| because after
323 // dropping the lock below |result| may no longer valid. 357 // dropping the lock below |result| may no longer valid.
324 Dart_Handle uri = 358 Dart_Handle uri =
325 Dart_NewStringFromCString(reinterpret_cast<char*>(result->uri)); 359 Dart_NewStringFromCString(reinterpret_cast<char*>(result->uri));
326 Dart_Handle resolved_uri = 360 Dart_Handle resolved_uri =
327 Dart_NewStringFromCString(reinterpret_cast<char*>(result->resolved_uri)); 361 Dart_NewStringFromCString(reinterpret_cast<char*>(result->resolved_uri));
328 Dart_Handle library_uri = Dart_Null(); 362 Dart_Handle library_uri = Dart_Null();
329 if (result->library_uri != NULL) { 363 if (result->library_uri != NULL) {
330 library_uri = 364 library_uri =
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 if (Dart_IsError(result)) { 415 if (Dart_IsError(result)) {
382 loader->error_ = result; 416 loader->error_ = result;
383 return false; 417 return false;
384 } 418 }
385 return true; 419 return true;
386 } 420 }
387 421
388 // Check for payload and load accordingly. 422 // Check for payload and load accordingly.
389 const uint8_t* payload = result->payload; 423 const uint8_t* payload = result->payload;
390 intptr_t payload_length = result->payload_length; 424 intptr_t payload_length = result->payload_length;
425
426 // Decompress if gzip'd.
427 ScopedDecompress decompress(&payload, &payload_length);
428
391 const DartUtils::MagicNumber payload_type = 429 const DartUtils::MagicNumber payload_type =
392 DartUtils::SniffForMagicNumber(&payload, &payload_length); 430 DartUtils::SniffForMagicNumber(payload, payload_length);
393 Dart_Handle source = Dart_Null(); 431 Dart_Handle source = Dart_Null();
394 if (payload_type == DartUtils::kUnknownMagicNumber) { 432 if (payload_type == DartUtils::kUnknownMagicNumber) {
395 source = Dart_NewStringFromUTF8(result->payload, result->payload_length); 433 source = Dart_NewStringFromUTF8(payload, payload_length);
396 if (Dart_IsError(source)) { 434 if (Dart_IsError(source)) {
397 loader->error_ = 435 loader->error_ =
398 DartUtils::NewError("%s is not a valid UTF-8 script", 436 DartUtils::NewError("%s is not a valid UTF-8 script",
399 reinterpret_cast<char*>(result->uri)); 437 reinterpret_cast<char*>(result->uri));
400 return false; 438 return false;
401 } 439 }
402 } 440 }
403 intptr_t tag = result->tag; 441 intptr_t tag = result->tag;
404 442
405 // No touching. 443 // No touching.
(...skipping 11 matching lines...) Expand all
417 dart_result = Dart_LoadLibrary(uri, resolved_uri, source, 0, 0); 455 dart_result = Dart_LoadLibrary(uri, resolved_uri, source, 0, 0);
418 break; 456 break;
419 case Dart_kSourceTag: { 457 case Dart_kSourceTag: {
420 ASSERT(library_uri != Dart_Null()); 458 ASSERT(library_uri != Dart_Null());
421 Dart_Handle library = Dart_LookupLibrary(library_uri); 459 Dart_Handle library = Dart_LookupLibrary(library_uri);
422 ASSERT(!Dart_IsError(library)); 460 ASSERT(!Dart_IsError(library));
423 dart_result = Dart_LoadSource(library, uri, resolved_uri, source, 0, 0); 461 dart_result = Dart_LoadSource(library, uri, resolved_uri, source, 0, 0);
424 } break; 462 } break;
425 case Dart_kScriptTag: 463 case Dart_kScriptTag:
426 if (payload_type == DartUtils::kSnapshotMagicNumber) { 464 if (payload_type == DartUtils::kSnapshotMagicNumber) {
465 DartUtils::SkipSnapshotMagicNumber(&payload, &payload_length);
427 dart_result = Dart_LoadScriptFromSnapshot(payload, payload_length); 466 dart_result = Dart_LoadScriptFromSnapshot(payload, payload_length);
428 reload_extensions = true; 467 reload_extensions = true;
429 } else if (payload_type == DartUtils::kKernelMagicNumber) { 468 } else if (payload_type == DartUtils::kKernelMagicNumber) {
430 // TODO(27590): This code path is only hit when trying to spawn 469 // TODO(27590): This code path is only hit when trying to spawn
431 // isolates. We currently do not have support for neither 470 // isolates. We currently do not have support for neither
432 // `Isolate.spawn()` nor `Isolate.spawnUri()` with kernel-based 471 // `Isolate.spawn()` nor `Isolate.spawnUri()` with kernel-based
433 // frontend. 472 // frontend.
434 Dart_Handle kernel_binary = reinterpret_cast<Dart_Handle>( 473 Dart_Handle kernel_binary = reinterpret_cast<Dart_Handle>(
435 Dart_ReadKernelBinary(payload, payload_length)); 474 Dart_ReadKernelBinary(payload, payload_length));
436 dart_result = Dart_LoadScript(uri, resolved_uri, kernel_binary, 0, 0); 475 dart_result = Dart_LoadScript(uri, resolved_uri, kernel_binary, 0, 0);
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 MutexLocker ml(loader_infos_lock_); 934 MutexLocker ml(loader_infos_lock_);
896 Loader* loader = LoaderForLocked(dest_port_id); 935 Loader* loader = LoaderForLocked(dest_port_id);
897 if (loader == NULL) { 936 if (loader == NULL) {
898 return; 937 return;
899 } 938 }
900 loader->QueueMessage(message); 939 loader->QueueMessage(message);
901 } 940 }
902 941
903 } // namespace bin 942 } // namespace bin
904 } // namespace dart 943 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/gzip.cc ('k') | runtime/bin/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698