[vm] Refactor handling of kernel data in compiler frontend

a) Remove 2 fields in our object representation:

  * PatchClass::library_data_
  * Library::kernel_data_

=> This saves O(#libraries + #patch-classes) which can amount up to
  10+ MB for big apps, as we save not just the slots but the
  [ExternalTypedData] objects they used to reference.

Instead we'll compute the KernelLibraryData when we need it by making a
[TypedDataView] of sub parts of the component.

b) We make a kernel binary be represented by a single [ExternalTypedData].

Whenever we need a sub-part of a kernel binary (e.g. one for each
component for concatinated kernels, or one for a library inside a
component) we use proper [TypedDataView]s for that.

c) As we sometimes need to create a view of only a particular library
within a component we need to find start/end of a library based on
index.

=> We store the library index instead of the library offset on
Library/PatchClass.
=> We can easily derive the start/end of a library from it's index by
looking at the kernel component encoding.

d) We make the [Reader] object work purely based on a pointer - instead
of making it have if/else when reading bytes (either from pointer or
from a view).

e) We make the [KernelProgramInfo] store the kernel_component and
various TD views into it.

TEST=ci

Change-Id: Ibe160881ff48635e834c3d647a977a144b5d0565
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313561
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
diff --git a/runtime/vm/app_snapshot.cc b/runtime/vm/app_snapshot.cc
index f6ad759..f0677f7 100644
--- a/runtime/vm/app_snapshot.cc
+++ b/runtime/vm/app_snapshot.cc
@@ -935,7 +935,7 @@
       AutoTraceObject(cls);
       WriteFromTo(cls);
       if (s->kind() != Snapshot::kFullAOT) {
-        s->Write<int32_t>(cls->untag()->library_kernel_offset_);
+        s->Write<int32_t>(cls->untag()->kernel_library_index_);
       }
     }
   }
@@ -965,7 +965,7 @@
       d.ReadFromTo(cls);
 #if !defined(DART_PRECOMPILED_RUNTIME)
       ASSERT(d_->kind() != Snapshot::kFullAOT);
-      cls->untag()->library_kernel_offset_ = d.Read<int32_t>();
+      cls->untag()->kernel_library_index_ = d.Read<int32_t>();
 #endif
     }
   }
@@ -1710,7 +1710,7 @@
       s->Write<int8_t>(lib->untag()->load_state_);
       s->Write<uint8_t>(lib->untag()->flags_);
       if (s->kind() != Snapshot::kFullAOT) {
-        s->Write<uint32_t>(lib->untag()->kernel_offset_);
+        s->Write<uint32_t>(lib->untag()->kernel_library_index_);
       }
     }
   }
@@ -1746,7 +1746,7 @@
           UntaggedLibrary::InFullSnapshotBit::update(true, d.Read<uint8_t>());
 #if !defined(DART_PRECOMPILED_RUNTIME)
       ASSERT(d_->kind() != Snapshot::kFullAOT);
-      lib->untag()->kernel_offset_ = d.Read<uint32_t>();
+      lib->untag()->kernel_library_index_ = d.Read<uint32_t>();
 #endif
     }
   }
diff --git a/runtime/vm/compiler/aot/precompiler.h b/runtime/vm/compiler/aot/precompiler.h
index 24eb743..657eade 100644
--- a/runtime/vm/compiler/aot/precompiler.h
+++ b/runtime/vm/compiler/aot/precompiler.h
@@ -207,7 +207,7 @@
       // of these might change during precompilation: urls are changed
       // by |Precompiler::Obfuscate| and library index is changed by
       // |Precompiler::DropLibraries|.
-      return Utils::WordHash(Library::Cast(*key).kernel_offset());
+      return Utils::WordHash(Library::Cast(*key).KernelLibraryOffset());
     }
     FATAL("Unexpected type: %s\n", key->ToCString());
   }
diff --git a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
index 3d6ec52..9190a70 100644
--- a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
+++ b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
@@ -275,7 +275,7 @@
         });
     constructor_initialized_field_offsets.Add(-1);
 
-    ExternalTypedData& kernel_data = ExternalTypedData::Handle(Z);
+    auto& kernel_data = TypedDataView::Handle(Z);
     Array& class_fields = Array::Handle(Z, parent_class.fields());
     Field& class_field = Field::Handle(Z);
     intptr_t next_constructor_initialized_field_index = 0;
@@ -298,7 +298,7 @@
           is_constructor_initialized = true;
         }
 
-        kernel_data = class_field.KernelData();
+        kernel_data = class_field.KernelLibrary();
         ASSERT(!kernel_data.IsNull());
         AlternativeReadingScopeWithNewData alt(&reader_, &kernel_data,
                                                field_offset);
diff --git a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.h b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.h
index f1ac36b..14c4e3d 100644
--- a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.h
+++ b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.h
@@ -23,13 +23,12 @@
 class StreamingFlowGraphBuilder : public KernelReaderHelper {
  public:
   StreamingFlowGraphBuilder(FlowGraphBuilder* flow_graph_builder,
-                            const ExternalTypedData& data,
+                            const TypedDataView& data,
                             intptr_t data_program_offset)
-      : KernelReaderHelper(
-            flow_graph_builder->zone_,
-            &flow_graph_builder->translation_helper_,
-            data,
-            data_program_offset),
+      : KernelReaderHelper(flow_graph_builder->zone_,
+                           &flow_graph_builder->translation_helper_,
+                           data,
+                           data_program_offset),
         flow_graph_builder_(flow_graph_builder),
         active_class_(&flow_graph_builder->active_class_),
         constant_reader_(this, active_class_),
diff --git a/runtime/vm/compiler/frontend/kernel_fingerprints.cc b/runtime/vm/compiler/frontend/kernel_fingerprints.cc
index 3f11921..7f29582 100644
--- a/runtime/vm/compiler/frontend/kernel_fingerprints.cc
+++ b/runtime/vm/compiler/frontend/kernel_fingerprints.cc
@@ -15,12 +15,9 @@
  public:
   KernelFingerprintHelper(Zone* zone,
                           TranslationHelper* translation_helper,
-                          const ExternalTypedData& data,
+                          const TypedDataView& data,
                           intptr_t data_program_offset)
-      : KernelReaderHelper(zone,
-                           translation_helper,
-                           data,
-                           data_program_offset),
+      : KernelReaderHelper(zone, translation_helper, data, data_program_offset),
         hash_(0) {}
 
   virtual ~KernelFingerprintHelper() {}
@@ -995,8 +992,8 @@
 
   KernelFingerprintHelper helper(
       zone, &translation_helper,
-      ExternalTypedData::Handle(zone, field.KernelData()),
-      field.KernelDataProgramOffset());
+      TypedDataView::Handle(zone, field.KernelLibrary()),
+      field.KernelLibraryOffset());
   helper.SetOffset(field.kernel_offset());
   return helper.CalculateFieldFingerprint();
 }
@@ -1012,8 +1009,8 @@
 
   KernelFingerprintHelper helper(
       zone, &translation_helper,
-      ExternalTypedData::Handle(zone, func.KernelData()),
-      func.KernelDataProgramOffset());
+      TypedDataView::Handle(zone, func.KernelLibrary()),
+      func.KernelLibraryOffset());
   helper.SetOffset(func.kernel_offset());
   return helper.CalculateFunctionFingerprint();
 }
diff --git a/runtime/vm/compiler/frontend/kernel_to_il.cc b/runtime/vm/compiler/frontend/kernel_to_il.cc
index a69ff23..4845de3 100644
--- a/runtime/vm/compiler/frontend/kernel_to_il.cc
+++ b/runtime/vm/compiler/frontend/kernel_to_il.cc
@@ -810,8 +810,8 @@
   }
 #endif
 
-  auto& kernel_data = ExternalTypedData::Handle(Z, function.KernelData());
-  intptr_t kernel_data_program_offset = function.KernelDataProgramOffset();
+  auto& kernel_data = TypedDataView::Handle(Z, function.KernelLibrary());
+  intptr_t kernel_data_program_offset = function.KernelLibraryOffset();
 
   StreamingFlowGraphBuilder streaming_flow_graph_builder(
       this, kernel_data, kernel_data_program_offset);
diff --git a/runtime/vm/compiler/frontend/kernel_translation_helper.cc b/runtime/vm/compiler/frontend/kernel_translation_helper.cc
index 7340665..119a082 100644
--- a/runtime/vm/compiler/frontend/kernel_translation_helper.cc
+++ b/runtime/vm/compiler/frontend/kernel_translation_helper.cc
@@ -29,12 +29,12 @@
       isolate_group_(thread->isolate_group()),
       allocation_space_(Heap::kNew),
       string_offsets_(TypedData::Handle(Z)),
-      string_data_(ExternalTypedData::Handle(Z)),
+      string_data_(TypedDataView::Handle(Z)),
       canonical_names_(TypedData::Handle(Z)),
-      metadata_payloads_(ExternalTypedData::Handle(Z)),
-      metadata_mappings_(ExternalTypedData::Handle(Z)),
+      metadata_payloads_(TypedDataView::Handle(Z)),
+      metadata_mappings_(TypedDataView::Handle(Z)),
       constants_(Array::Handle(Z)),
-      constants_table_(ExternalTypedData::Handle(Z)),
+      constants_table_(TypedDataView::Handle(Z)),
       info_(KernelProgramInfo::Handle(Z)),
       name_index_handle_(Smi::Handle(Z)) {}
 
@@ -44,21 +44,21 @@
       isolate_group_(thread->isolate_group()),
       allocation_space_(space),
       string_offsets_(TypedData::Handle(Z)),
-      string_data_(ExternalTypedData::Handle(Z)),
+      string_data_(TypedDataView::Handle(Z)),
       canonical_names_(TypedData::Handle(Z)),
-      metadata_payloads_(ExternalTypedData::Handle(Z)),
-      metadata_mappings_(ExternalTypedData::Handle(Z)),
+      metadata_payloads_(TypedDataView::Handle(Z)),
+      metadata_mappings_(TypedDataView::Handle(Z)),
       constants_(Array::Handle(Z)),
-      constants_table_(ExternalTypedData::Handle(Z)),
+      constants_table_(TypedDataView::Handle(Z)),
       info_(KernelProgramInfo::Handle(Z)),
       name_index_handle_(Smi::Handle(Z)) {}
 
 void TranslationHelper::Reset() {
   string_offsets_ = TypedData::null();
-  string_data_ = ExternalTypedData::null();
+  string_data_ = TypedDataView::null();
   canonical_names_ = TypedData::null();
-  metadata_payloads_ = ExternalTypedData::null();
-  metadata_mappings_ = ExternalTypedData::null();
+  metadata_payloads_ = TypedDataView::null();
+  metadata_mappings_ = TypedDataView::null();
   constants_ = Array::null();
 }
 
@@ -71,12 +71,12 @@
     return;
   }
   SetStringOffsets(TypedData::Handle(Z, info.string_offsets()));
-  SetStringData(ExternalTypedData::Handle(Z, info.string_data()));
+  SetStringData(TypedDataView::Handle(Z, info.string_data()));
   SetCanonicalNames(TypedData::Handle(Z, info.canonical_names()));
-  SetMetadataPayloads(ExternalTypedData::Handle(Z, info.metadata_payloads()));
-  SetMetadataMappings(ExternalTypedData::Handle(Z, info.metadata_mappings()));
+  SetMetadataPayloads(TypedDataView::Handle(Z, info.metadata_payloads()));
+  SetMetadataMappings(TypedDataView::Handle(Z, info.metadata_mappings()));
   SetConstants(Array::Handle(Z, info.constants()));
-  SetConstantsTable(ExternalTypedData::Handle(Z, info.constants_table()));
+  SetConstantsTable(TypedDataView::Handle(Z, info.constants_table()));
   SetKernelProgramInfo(info);
 }
 
@@ -85,7 +85,7 @@
   string_offsets_ = string_offsets.ptr();
 }
 
-void TranslationHelper::SetStringData(const ExternalTypedData& string_data) {
+void TranslationHelper::SetStringData(const TypedDataView& string_data) {
   ASSERT(string_data_.IsNull());
   string_data_ = string_data.ptr();
 }
@@ -96,14 +96,14 @@
 }
 
 void TranslationHelper::SetMetadataPayloads(
-    const ExternalTypedData& metadata_payloads) {
+    const TypedDataView& metadata_payloads) {
   ASSERT(metadata_payloads_.IsNull());
   ASSERT(Utils::IsAligned(metadata_payloads.DataAddr(0), kWordSize));
   metadata_payloads_ = metadata_payloads.ptr();
 }
 
 void TranslationHelper::SetMetadataMappings(
-    const ExternalTypedData& metadata_mappings) {
+    const TypedDataView& metadata_mappings) {
   ASSERT(metadata_mappings_.IsNull());
   metadata_mappings_ = metadata_mappings.ptr();
 }
@@ -115,7 +115,7 @@
 }
 
 void TranslationHelper::SetConstantsTable(
-    const ExternalTypedData& constants_table) {
+    const TypedDataView& constants_table) {
   ASSERT(constants_table_.IsNull());
   constants_table_ = constants_table.ptr();
 }
@@ -1520,7 +1520,7 @@
 #if defined(DEBUG)
 
 void MetadataHelper::VerifyMetadataMappings(
-    const ExternalTypedData& metadata_mappings) {
+    const TypedDataView& metadata_mappings) {
   const intptr_t kUInt32Size = 4;
   Reader reader(metadata_mappings);
   if (reader.size() == 0) {
@@ -3067,8 +3067,7 @@
   return H.DartString(reader_.BufferAt(ReaderOffset()), size, Heap::kOld);
 }
 
-ExternalTypedDataPtr KernelReaderHelper::GetConstantCoverageFor(
-    intptr_t index) {
+TypedDataViewPtr KernelReaderHelper::GetConstantCoverageFor(intptr_t index) {
   AlternativeReadingScope alt(&reader_);
   SetOffset(GetOffsetForSourceInfo(index));
   SkipBytes(ReadUInt());                         // skip uri.
@@ -3091,7 +3090,7 @@
 
   intptr_t end_offset = ReaderOffset();
 
-  return reader_.ExternalDataFromTo(start_offset, end_offset);
+  return reader_.ViewFromTo(start_offset, end_offset);
 }
 
 intptr_t ActiveClass::MemberTypeParameterCount(Zone* zone) {
diff --git a/runtime/vm/compiler/frontend/kernel_translation_helper.h b/runtime/vm/compiler/frontend/kernel_translation_helper.h
index 3958971..03f862c 100644
--- a/runtime/vm/compiler/frontend/kernel_translation_helper.h
+++ b/runtime/vm/compiler/frontend/kernel_translation_helper.h
@@ -46,29 +46,25 @@
   const TypedData& string_offsets() const { return string_offsets_; }
   void SetStringOffsets(const TypedData& string_offsets);
 
-  const ExternalTypedData& string_data() const { return string_data_; }
-  void SetStringData(const ExternalTypedData& string_data);
+  const TypedDataView& string_data() const { return string_data_; }
+  void SetStringData(const TypedDataView& string_data);
 
   const TypedData& canonical_names() const { return canonical_names_; }
   void SetCanonicalNames(const TypedData& canonical_names);
 
-  const ExternalTypedData& metadata_payloads() const {
-    return metadata_payloads_;
-  }
-  void SetMetadataPayloads(const ExternalTypedData& metadata_payloads);
+  const TypedDataView& metadata_payloads() const { return metadata_payloads_; }
+  void SetMetadataPayloads(const TypedDataView& metadata_payloads);
 
-  const ExternalTypedData& metadata_mappings() const {
-    return metadata_mappings_;
-  }
-  void SetMetadataMappings(const ExternalTypedData& metadata_mappings);
+  const TypedDataView& metadata_mappings() const { return metadata_mappings_; }
+  void SetMetadataMappings(const TypedDataView& metadata_mappings);
 
   // Access to previously evaluated constants from the constants table.
   const Array& constants() { return constants_; }
   void SetConstants(const Array& constants);
 
   // Access to the raw bytes of the constants table.
-  const ExternalTypedData& constants_table() const { return constants_table_; }
-  void SetConstantsTable(const ExternalTypedData& constants_table);
+  const TypedDataView& constants_table() const { return constants_table_; }
+  void SetConstantsTable(const TypedDataView& constants_table);
 
   void SetKernelProgramInfo(const KernelProgramInfo& info);
   const KernelProgramInfo& GetKernelProgramInfo() const { return info_; }
@@ -251,12 +247,12 @@
   Heap::Space allocation_space_;
 
   TypedData& string_offsets_;
-  ExternalTypedData& string_data_;
+  TypedDataView& string_data_;
   TypedData& canonical_names_;
-  ExternalTypedData& metadata_payloads_;
-  ExternalTypedData& metadata_mappings_;
+  TypedDataView& metadata_payloads_;
+  TypedDataView& metadata_mappings_;
   Array& constants_;
-  ExternalTypedData& constants_table_;
+  TypedDataView& constants_table_;
   KernelProgramInfo& info_;
   Smi& name_index_handle_;
   GrowableObjectArray* potential_extension_libraries_ = nullptr;
@@ -945,8 +941,7 @@
                  bool precompiler_only);
 
 #if defined(DEBUG)
-  static void VerifyMetadataMappings(
-      const ExternalTypedData& metadata_mappings);
+  static void VerifyMetadataMappings(const TypedDataView& metadata_mappings);
 #endif
 
  protected:
@@ -1235,22 +1230,13 @@
  public:
   KernelReaderHelper(Zone* zone,
                      TranslationHelper* translation_helper,
-                     const ExternalTypedData& data,
+                     const TypedDataBase& data,
                      intptr_t data_program_offset)
       : zone_(zone),
         translation_helper_(*translation_helper),
         reader_(data),
         data_program_offset_(data_program_offset) {}
 
-  KernelReaderHelper(Zone* zone,
-                     TranslationHelper* translation_helper,
-                     const ProgramBinary& binary,
-                     intptr_t data_program_offset)
-      : zone_(zone),
-        translation_helper_(*translation_helper),
-        reader_(binary),
-        data_program_offset_(data_program_offset) {}
-
   virtual ~KernelReaderHelper() = default;
 
   void SetOffset(intptr_t offset);
@@ -1332,7 +1318,7 @@
   const String& GetSourceFor(intptr_t index);
   TypedDataPtr GetLineStartsFor(intptr_t index);
   String& SourceTableImportUriFor(intptr_t index);
-  ExternalTypedDataPtr GetConstantCoverageFor(intptr_t index);
+  TypedDataViewPtr GetConstantCoverageFor(intptr_t index);
 
   Zone* zone_;
   TranslationHelper& translation_helper_;
diff --git a/runtime/vm/compiler/frontend/scope_builder.cc b/runtime/vm/compiler/frontend/scope_builder.cc
index 57a5dd4..76a4c3d 100644
--- a/runtime/vm/compiler/frontend/scope_builder.cc
+++ b/runtime/vm/compiler/frontend/scope_builder.cc
@@ -29,9 +29,8 @@
       helper_(
           zone_,
           &translation_helper_,
-          ExternalTypedData::Handle(Z,
-                                    parsed_function->function().KernelData()),
-          parsed_function->function().KernelDataProgramOffset()),
+          TypedDataView::Handle(Z, parsed_function->function().KernelLibrary()),
+          parsed_function->function().KernelLibraryOffset()),
       constant_reader_(&helper_, &active_class_),
       inferred_type_metadata_helper_(&helper_, &constant_reader_),
       procedure_attributes_metadata_helper_(&helper_),
@@ -178,8 +177,8 @@
           for (intptr_t i = 0; i < class_fields.Length(); ++i) {
             class_field ^= class_fields.At(i);
             if (!class_field.is_static()) {
-              ExternalTypedData& kernel_data =
-                  ExternalTypedData::Handle(Z, class_field.KernelData());
+              const auto& kernel_data =
+                  TypedDataView::Handle(Z, class_field.KernelLibrary());
               ASSERT(!kernel_data.IsNull());
               intptr_t field_offset = class_field.kernel_offset();
               AlternativeReadingScopeWithNewData alt(
@@ -507,8 +506,8 @@
     for (intptr_t i = 0; i < class_fields.Length(); ++i) {
       class_field ^= class_fields.At(i);
       if (!class_field.is_static()) {
-        ExternalTypedData& kernel_data =
-            ExternalTypedData::Handle(Z, class_field.KernelData());
+        const auto& kernel_data =
+            TypedDataView::Handle(Z, class_field.KernelLibrary());
         ASSERT(!kernel_data.IsNull());
         intptr_t field_offset = class_field.kernel_offset();
         AlternativeReadingScopeWithNewData alt(&helper_.reader_, &kernel_data,
@@ -1896,8 +1895,7 @@
 StringIndex ScopeBuilder::GetNameFromVariableDeclaration(
     intptr_t kernel_offset,
     const Function& function) {
-  ExternalTypedData& kernel_data =
-      ExternalTypedData::Handle(Z, function.KernelData());
+  const auto& kernel_data = TypedDataView::Handle(Z, function.KernelLibrary());
   ASSERT(!kernel_data.IsNull());
 
   // Temporarily go to the variable declaration, read the name.
diff --git a/runtime/vm/compiler/runtime_offsets_extracted.h b/runtime/vm/compiler/runtime_offsets_extracted.h
index 6a081ff..21148e0 100644
--- a/runtime/vm/compiler/runtime_offsets_extracted.h
+++ b/runtime/vm/compiler/runtime_offsets_extracted.h
@@ -670,7 +670,7 @@
 static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
     0x30;
 static constexpr dart::compiler::target::word LanguageError_InstanceSize = 0x1c;
-static constexpr dart::compiler::target::word Library_InstanceSize = 0x5c;
+static constexpr dart::compiler::target::word Library_InstanceSize = 0x58;
 static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 0x14;
 static constexpr dart::compiler::target::word LinkedHashBase_InstanceSize =
     0x1c;
@@ -686,7 +686,7 @@
 static constexpr dart::compiler::target::word NativeArguments_StructSize = 0x10;
 static constexpr dart::compiler::target::word Number_InstanceSize = 0x4;
 static constexpr dart::compiler::target::word Object_InstanceSize = 0x4;
-static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x18;
+static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x14;
 static constexpr dart::compiler::target::word PcDescriptors_HeaderSize = 0x8;
 static constexpr dart::compiler::target::word Pointer_InstanceSize = 0xc;
 static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 0x14;
@@ -1386,7 +1386,7 @@
 static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
     0x60;
 static constexpr dart::compiler::target::word LanguageError_InstanceSize = 0x30;
-static constexpr dart::compiler::target::word Library_InstanceSize = 0xb0;
+static constexpr dart::compiler::target::word Library_InstanceSize = 0xa8;
 static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 0x28;
 static constexpr dart::compiler::target::word LinkedHashBase_InstanceSize =
     0x38;
@@ -1402,7 +1402,7 @@
 static constexpr dart::compiler::target::word NativeArguments_StructSize = 0x20;
 static constexpr dart::compiler::target::word Number_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word Object_InstanceSize = 0x8;
-static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x30;
+static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x28;
 static constexpr dart::compiler::target::word PcDescriptors_HeaderSize = 0x10;
 static constexpr dart::compiler::target::word Pointer_InstanceSize = 0x18;
 static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 0x28;
@@ -2091,7 +2091,7 @@
 static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
     0x30;
 static constexpr dart::compiler::target::word LanguageError_InstanceSize = 0x1c;
-static constexpr dart::compiler::target::word Library_InstanceSize = 0x5c;
+static constexpr dart::compiler::target::word Library_InstanceSize = 0x58;
 static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 0x14;
 static constexpr dart::compiler::target::word LinkedHashBase_InstanceSize =
     0x1c;
@@ -2107,7 +2107,7 @@
 static constexpr dart::compiler::target::word NativeArguments_StructSize = 0x10;
 static constexpr dart::compiler::target::word Number_InstanceSize = 0x4;
 static constexpr dart::compiler::target::word Object_InstanceSize = 0x4;
-static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x18;
+static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x14;
 static constexpr dart::compiler::target::word PcDescriptors_HeaderSize = 0x8;
 static constexpr dart::compiler::target::word Pointer_InstanceSize = 0xc;
 static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 0x14;
@@ -2809,7 +2809,7 @@
 static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
     0x60;
 static constexpr dart::compiler::target::word LanguageError_InstanceSize = 0x30;
-static constexpr dart::compiler::target::word Library_InstanceSize = 0xb0;
+static constexpr dart::compiler::target::word Library_InstanceSize = 0xa8;
 static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 0x28;
 static constexpr dart::compiler::target::word LinkedHashBase_InstanceSize =
     0x38;
@@ -2825,7 +2825,7 @@
 static constexpr dart::compiler::target::word NativeArguments_StructSize = 0x20;
 static constexpr dart::compiler::target::word Number_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word Object_InstanceSize = 0x8;
-static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x30;
+static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x28;
 static constexpr dart::compiler::target::word PcDescriptors_HeaderSize = 0x10;
 static constexpr dart::compiler::target::word Pointer_InstanceSize = 0x18;
 static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 0x28;
@@ -4942,7 +4942,7 @@
 static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
     0x30;
 static constexpr dart::compiler::target::word LanguageError_InstanceSize = 0x1c;
-static constexpr dart::compiler::target::word Library_InstanceSize = 0x5c;
+static constexpr dart::compiler::target::word Library_InstanceSize = 0x58;
 static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 0x14;
 static constexpr dart::compiler::target::word LinkedHashBase_InstanceSize =
     0x1c;
@@ -4958,7 +4958,7 @@
 static constexpr dart::compiler::target::word NativeArguments_StructSize = 0x10;
 static constexpr dart::compiler::target::word Number_InstanceSize = 0x4;
 static constexpr dart::compiler::target::word Object_InstanceSize = 0x4;
-static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x18;
+static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x14;
 static constexpr dart::compiler::target::word PcDescriptors_HeaderSize = 0x8;
 static constexpr dart::compiler::target::word Pointer_InstanceSize = 0xc;
 static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 0x14;
@@ -5659,7 +5659,7 @@
 static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
     0x60;
 static constexpr dart::compiler::target::word LanguageError_InstanceSize = 0x30;
-static constexpr dart::compiler::target::word Library_InstanceSize = 0xb0;
+static constexpr dart::compiler::target::word Library_InstanceSize = 0xa8;
 static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 0x28;
 static constexpr dart::compiler::target::word LinkedHashBase_InstanceSize =
     0x38;
@@ -5675,7 +5675,7 @@
 static constexpr dart::compiler::target::word NativeArguments_StructSize = 0x20;
 static constexpr dart::compiler::target::word Number_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word Object_InstanceSize = 0x8;
-static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x30;
+static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x28;
 static constexpr dart::compiler::target::word PcDescriptors_HeaderSize = 0x10;
 static constexpr dart::compiler::target::word Pointer_InstanceSize = 0x18;
 static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 0x28;
@@ -6359,7 +6359,7 @@
 static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
     0x30;
 static constexpr dart::compiler::target::word LanguageError_InstanceSize = 0x1c;
-static constexpr dart::compiler::target::word Library_InstanceSize = 0x5c;
+static constexpr dart::compiler::target::word Library_InstanceSize = 0x58;
 static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 0x14;
 static constexpr dart::compiler::target::word LinkedHashBase_InstanceSize =
     0x1c;
@@ -6375,7 +6375,7 @@
 static constexpr dart::compiler::target::word NativeArguments_StructSize = 0x10;
 static constexpr dart::compiler::target::word Number_InstanceSize = 0x4;
 static constexpr dart::compiler::target::word Object_InstanceSize = 0x4;
-static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x18;
+static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x14;
 static constexpr dart::compiler::target::word PcDescriptors_HeaderSize = 0x8;
 static constexpr dart::compiler::target::word Pointer_InstanceSize = 0xc;
 static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 0xc;
@@ -7067,7 +7067,7 @@
 static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
     0x60;
 static constexpr dart::compiler::target::word LanguageError_InstanceSize = 0x30;
-static constexpr dart::compiler::target::word Library_InstanceSize = 0xb0;
+static constexpr dart::compiler::target::word Library_InstanceSize = 0xa8;
 static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 0x28;
 static constexpr dart::compiler::target::word LinkedHashBase_InstanceSize =
     0x38;
@@ -7083,7 +7083,7 @@
 static constexpr dart::compiler::target::word NativeArguments_StructSize = 0x20;
 static constexpr dart::compiler::target::word Number_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word Object_InstanceSize = 0x8;
-static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x30;
+static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x28;
 static constexpr dart::compiler::target::word PcDescriptors_HeaderSize = 0x10;
 static constexpr dart::compiler::target::word Pointer_InstanceSize = 0x18;
 static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 0x18;
@@ -7764,7 +7764,7 @@
 static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
     0x30;
 static constexpr dart::compiler::target::word LanguageError_InstanceSize = 0x1c;
-static constexpr dart::compiler::target::word Library_InstanceSize = 0x5c;
+static constexpr dart::compiler::target::word Library_InstanceSize = 0x58;
 static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 0x14;
 static constexpr dart::compiler::target::word LinkedHashBase_InstanceSize =
     0x1c;
@@ -7780,7 +7780,7 @@
 static constexpr dart::compiler::target::word NativeArguments_StructSize = 0x10;
 static constexpr dart::compiler::target::word Number_InstanceSize = 0x4;
 static constexpr dart::compiler::target::word Object_InstanceSize = 0x4;
-static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x18;
+static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x14;
 static constexpr dart::compiler::target::word PcDescriptors_HeaderSize = 0x8;
 static constexpr dart::compiler::target::word Pointer_InstanceSize = 0xc;
 static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 0xc;
@@ -8474,7 +8474,7 @@
 static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
     0x60;
 static constexpr dart::compiler::target::word LanguageError_InstanceSize = 0x30;
-static constexpr dart::compiler::target::word Library_InstanceSize = 0xb0;
+static constexpr dart::compiler::target::word Library_InstanceSize = 0xa8;
 static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 0x28;
 static constexpr dart::compiler::target::word LinkedHashBase_InstanceSize =
     0x38;
@@ -8490,7 +8490,7 @@
 static constexpr dart::compiler::target::word NativeArguments_StructSize = 0x20;
 static constexpr dart::compiler::target::word Number_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word Object_InstanceSize = 0x8;
-static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x30;
+static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x28;
 static constexpr dart::compiler::target::word PcDescriptors_HeaderSize = 0x10;
 static constexpr dart::compiler::target::word Pointer_InstanceSize = 0x18;
 static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 0x18;
@@ -10583,7 +10583,7 @@
 static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
     0x30;
 static constexpr dart::compiler::target::word LanguageError_InstanceSize = 0x1c;
-static constexpr dart::compiler::target::word Library_InstanceSize = 0x5c;
+static constexpr dart::compiler::target::word Library_InstanceSize = 0x58;
 static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 0x14;
 static constexpr dart::compiler::target::word LinkedHashBase_InstanceSize =
     0x1c;
@@ -10599,7 +10599,7 @@
 static constexpr dart::compiler::target::word NativeArguments_StructSize = 0x10;
 static constexpr dart::compiler::target::word Number_InstanceSize = 0x4;
 static constexpr dart::compiler::target::word Object_InstanceSize = 0x4;
-static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x18;
+static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x14;
 static constexpr dart::compiler::target::word PcDescriptors_HeaderSize = 0x8;
 static constexpr dart::compiler::target::word Pointer_InstanceSize = 0xc;
 static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 0xc;
@@ -11292,7 +11292,7 @@
 static constexpr dart::compiler::target::word KernelProgramInfo_InstanceSize =
     0x60;
 static constexpr dart::compiler::target::word LanguageError_InstanceSize = 0x30;
-static constexpr dart::compiler::target::word Library_InstanceSize = 0xb0;
+static constexpr dart::compiler::target::word Library_InstanceSize = 0xa8;
 static constexpr dart::compiler::target::word LibraryPrefix_InstanceSize = 0x28;
 static constexpr dart::compiler::target::word LinkedHashBase_InstanceSize =
     0x38;
@@ -11308,7 +11308,7 @@
 static constexpr dart::compiler::target::word NativeArguments_StructSize = 0x20;
 static constexpr dart::compiler::target::word Number_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word Object_InstanceSize = 0x8;
-static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x30;
+static constexpr dart::compiler::target::word PatchClass_InstanceSize = 0x28;
 static constexpr dart::compiler::target::word PcDescriptors_HeaderSize = 0x10;
 static constexpr dart::compiler::target::word Pointer_InstanceSize = 0x18;
 static constexpr dart::compiler::target::word ReceivePort_InstanceSize = 0x18;
@@ -12066,7 +12066,7 @@
     AOT_KernelProgramInfo_InstanceSize = 0x30;
 static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
     0x1c;
-static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x54;
+static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x50;
 static constexpr dart::compiler::target::word AOT_LibraryPrefix_InstanceSize =
     0x14;
 static constexpr dart::compiler::target::word AOT_LinkedHashBase_InstanceSize =
@@ -12085,8 +12085,7 @@
     0x10;
 static constexpr dart::compiler::target::word AOT_Number_InstanceSize = 0x4;
 static constexpr dart::compiler::target::word AOT_Object_InstanceSize = 0x4;
-static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize =
-    0x10;
+static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize = 0xc;
 static constexpr dart::compiler::target::word AOT_PcDescriptors_HeaderSize =
     0x8;
 static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 0xc;
@@ -12853,7 +12852,7 @@
     AOT_KernelProgramInfo_InstanceSize = 0x60;
 static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
     0x30;
-static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0xa0;
+static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x98;
 static constexpr dart::compiler::target::word AOT_LibraryPrefix_InstanceSize =
     0x28;
 static constexpr dart::compiler::target::word AOT_LinkedHashBase_InstanceSize =
@@ -12873,7 +12872,7 @@
 static constexpr dart::compiler::target::word AOT_Number_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_Object_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize =
-    0x20;
+    0x18;
 static constexpr dart::compiler::target::word AOT_PcDescriptors_HeaderSize =
     0x10;
 static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 0x18;
@@ -13645,7 +13644,7 @@
     AOT_KernelProgramInfo_InstanceSize = 0x60;
 static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
     0x30;
-static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0xa0;
+static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x98;
 static constexpr dart::compiler::target::word AOT_LibraryPrefix_InstanceSize =
     0x28;
 static constexpr dart::compiler::target::word AOT_LinkedHashBase_InstanceSize =
@@ -13665,7 +13664,7 @@
 static constexpr dart::compiler::target::word AOT_Number_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_Object_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize =
-    0x20;
+    0x18;
 static constexpr dart::compiler::target::word AOT_PcDescriptors_HeaderSize =
     0x10;
 static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 0x18;
@@ -14434,7 +14433,7 @@
     AOT_KernelProgramInfo_InstanceSize = 0x38;
 static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
     0x20;
-static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x68;
+static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x60;
 static constexpr dart::compiler::target::word AOT_LibraryPrefix_InstanceSize =
     0x18;
 static constexpr dart::compiler::target::word AOT_LinkedHashBase_InstanceSize =
@@ -14454,7 +14453,7 @@
 static constexpr dart::compiler::target::word AOT_Number_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_Object_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize =
-    0x18;
+    0x10;
 static constexpr dart::compiler::target::word AOT_PcDescriptors_HeaderSize =
     0x10;
 static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 0x18;
@@ -15225,7 +15224,7 @@
     AOT_KernelProgramInfo_InstanceSize = 0x38;
 static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
     0x20;
-static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x68;
+static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x60;
 static constexpr dart::compiler::target::word AOT_LibraryPrefix_InstanceSize =
     0x18;
 static constexpr dart::compiler::target::word AOT_LinkedHashBase_InstanceSize =
@@ -15245,7 +15244,7 @@
 static constexpr dart::compiler::target::word AOT_Number_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_Object_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize =
-    0x18;
+    0x10;
 static constexpr dart::compiler::target::word AOT_PcDescriptors_HeaderSize =
     0x10;
 static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 0x18;
@@ -16013,7 +16012,7 @@
     AOT_KernelProgramInfo_InstanceSize = 0x30;
 static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
     0x1c;
-static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x54;
+static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x50;
 static constexpr dart::compiler::target::word AOT_LibraryPrefix_InstanceSize =
     0x14;
 static constexpr dart::compiler::target::word AOT_LinkedHashBase_InstanceSize =
@@ -16032,8 +16031,7 @@
     0x10;
 static constexpr dart::compiler::target::word AOT_Number_InstanceSize = 0x4;
 static constexpr dart::compiler::target::word AOT_Object_InstanceSize = 0x4;
-static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize =
-    0x10;
+static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize = 0xc;
 static constexpr dart::compiler::target::word AOT_PcDescriptors_HeaderSize =
     0x8;
 static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 0xc;
@@ -16801,7 +16799,7 @@
     AOT_KernelProgramInfo_InstanceSize = 0x60;
 static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
     0x30;
-static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0xa0;
+static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x98;
 static constexpr dart::compiler::target::word AOT_LibraryPrefix_InstanceSize =
     0x28;
 static constexpr dart::compiler::target::word AOT_LinkedHashBase_InstanceSize =
@@ -16821,7 +16819,7 @@
 static constexpr dart::compiler::target::word AOT_Number_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_Object_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize =
-    0x20;
+    0x18;
 static constexpr dart::compiler::target::word AOT_PcDescriptors_HeaderSize =
     0x10;
 static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 0x18;
@@ -17581,7 +17579,7 @@
     AOT_KernelProgramInfo_InstanceSize = 0x30;
 static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
     0x1c;
-static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x54;
+static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x50;
 static constexpr dart::compiler::target::word AOT_LibraryPrefix_InstanceSize =
     0x14;
 static constexpr dart::compiler::target::word AOT_LinkedHashBase_InstanceSize =
@@ -17600,8 +17598,7 @@
     0x10;
 static constexpr dart::compiler::target::word AOT_Number_InstanceSize = 0x4;
 static constexpr dart::compiler::target::word AOT_Object_InstanceSize = 0x4;
-static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize =
-    0x10;
+static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize = 0xc;
 static constexpr dart::compiler::target::word AOT_PcDescriptors_HeaderSize =
     0x8;
 static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 0xc;
@@ -18359,7 +18356,7 @@
     AOT_KernelProgramInfo_InstanceSize = 0x60;
 static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
     0x30;
-static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0xa0;
+static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x98;
 static constexpr dart::compiler::target::word AOT_LibraryPrefix_InstanceSize =
     0x28;
 static constexpr dart::compiler::target::word AOT_LinkedHashBase_InstanceSize =
@@ -18379,7 +18376,7 @@
 static constexpr dart::compiler::target::word AOT_Number_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_Object_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize =
-    0x20;
+    0x18;
 static constexpr dart::compiler::target::word AOT_PcDescriptors_HeaderSize =
     0x10;
 static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 0x18;
@@ -19142,7 +19139,7 @@
     AOT_KernelProgramInfo_InstanceSize = 0x60;
 static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
     0x30;
-static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0xa0;
+static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x98;
 static constexpr dart::compiler::target::word AOT_LibraryPrefix_InstanceSize =
     0x28;
 static constexpr dart::compiler::target::word AOT_LinkedHashBase_InstanceSize =
@@ -19162,7 +19159,7 @@
 static constexpr dart::compiler::target::word AOT_Number_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_Object_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize =
-    0x20;
+    0x18;
 static constexpr dart::compiler::target::word AOT_PcDescriptors_HeaderSize =
     0x10;
 static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 0x18;
@@ -19922,7 +19919,7 @@
     AOT_KernelProgramInfo_InstanceSize = 0x38;
 static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
     0x20;
-static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x68;
+static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x60;
 static constexpr dart::compiler::target::word AOT_LibraryPrefix_InstanceSize =
     0x18;
 static constexpr dart::compiler::target::word AOT_LinkedHashBase_InstanceSize =
@@ -19942,7 +19939,7 @@
 static constexpr dart::compiler::target::word AOT_Number_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_Object_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize =
-    0x18;
+    0x10;
 static constexpr dart::compiler::target::word AOT_PcDescriptors_HeaderSize =
     0x10;
 static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 0x18;
@@ -20704,7 +20701,7 @@
     AOT_KernelProgramInfo_InstanceSize = 0x38;
 static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
     0x20;
-static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x68;
+static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x60;
 static constexpr dart::compiler::target::word AOT_LibraryPrefix_InstanceSize =
     0x18;
 static constexpr dart::compiler::target::word AOT_LinkedHashBase_InstanceSize =
@@ -20724,7 +20721,7 @@
 static constexpr dart::compiler::target::word AOT_Number_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_Object_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize =
-    0x18;
+    0x10;
 static constexpr dart::compiler::target::word AOT_PcDescriptors_HeaderSize =
     0x10;
 static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 0x18;
@@ -21483,7 +21480,7 @@
     AOT_KernelProgramInfo_InstanceSize = 0x30;
 static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
     0x1c;
-static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x54;
+static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x50;
 static constexpr dart::compiler::target::word AOT_LibraryPrefix_InstanceSize =
     0x14;
 static constexpr dart::compiler::target::word AOT_LinkedHashBase_InstanceSize =
@@ -21502,8 +21499,7 @@
     0x10;
 static constexpr dart::compiler::target::word AOT_Number_InstanceSize = 0x4;
 static constexpr dart::compiler::target::word AOT_Object_InstanceSize = 0x4;
-static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize =
-    0x10;
+static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize = 0xc;
 static constexpr dart::compiler::target::word AOT_PcDescriptors_HeaderSize =
     0x8;
 static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 0xc;
@@ -22262,7 +22258,7 @@
     AOT_KernelProgramInfo_InstanceSize = 0x60;
 static constexpr dart::compiler::target::word AOT_LanguageError_InstanceSize =
     0x30;
-static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0xa0;
+static constexpr dart::compiler::target::word AOT_Library_InstanceSize = 0x98;
 static constexpr dart::compiler::target::word AOT_LibraryPrefix_InstanceSize =
     0x28;
 static constexpr dart::compiler::target::word AOT_LinkedHashBase_InstanceSize =
@@ -22282,7 +22278,7 @@
 static constexpr dart::compiler::target::word AOT_Number_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_Object_InstanceSize = 0x8;
 static constexpr dart::compiler::target::word AOT_PatchClass_InstanceSize =
-    0x20;
+    0x18;
 static constexpr dart::compiler::target::word AOT_PcDescriptors_HeaderSize =
     0x10;
 static constexpr dart::compiler::target::word AOT_Pointer_InstanceSize = 0x18;
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index d01988b..b6f2b3d 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -6241,11 +6241,10 @@
   // kernel file or the kernel file of the application,
   // figure out the null safety mode by sniffing the kernel file.
   if (kernel_buffer != nullptr) {
-    const char* error = nullptr;
-    std::unique_ptr<kernel::Program> program = kernel::Program::ReadFromBuffer(
-        kernel_buffer, kernel_buffer_size, &error);
-    if (program != nullptr) {
-      return program->compilation_mode() == NNBDCompiledMode::kStrong;
+    const auto null_safety =
+        kernel::Program::DetectNullSafety(kernel_buffer, kernel_buffer_size);
+    if (null_safety != NNBDCompiledMode::kInvalid) {
+      return null_safety == NNBDCompiledMode::kStrong;
     }
   }
 #endif
diff --git a/runtime/vm/isolate_reload.cc b/runtime/vm/isolate_reload.cc
index 2f4725c..42d1727 100644
--- a/runtime/vm/isolate_reload.cc
+++ b/runtime/vm/isolate_reload.cc
@@ -825,7 +825,7 @@
     kernel_program = kernel::Program::ReadFromFile(root_script_url);
     if (kernel_program != nullptr) {
       num_received_libs_ = kernel_program->library_count();
-      bytes_received_libs_ = kernel_program->kernel_data_size();
+      bytes_received_libs_ = kernel_program->binary().LengthInBytes();
       p_num_received_classes = &num_received_classes_;
       p_num_received_procedures = &num_received_procedures_;
     } else {
@@ -854,10 +854,9 @@
 
     NoActiveIsolateScope no_active_isolate_scope;
 
-    ExternalTypedData& external_typed_data =
-        ExternalTypedData::Handle(Z, kernel_program->typed_data()->ptr());
     IsolateGroupSource* source = IsolateGroup::Current()->source();
-    source->add_loaded_blob(Z, external_typed_data);
+    source->add_loaded_blob(Z,
+                            ExternalTypedData::Cast(kernel_program->binary()));
 
     modified_libs_ = new (Z) BitVector(Z, num_old_libs_);
     kernel::KernelLoader::FindModifiedLibraries(
diff --git a/runtime/vm/kernel.cc b/runtime/vm/kernel.cc
index e1c6275..ebb50f8 100644
--- a/runtime/vm/kernel.cc
+++ b/runtime/vm/kernel.cc
@@ -106,15 +106,12 @@
       Zone* zone,
       TranslationHelper* translation_helper,
       const Script& script,
-      const ExternalTypedData& data,
+      const TypedDataView& data,
       intptr_t data_program_offset,
       intptr_t initial_script_index,
       intptr_t record_for_script_id,
       GrowableArray<intptr_t>* record_token_positions_into)
-      : KernelReaderHelper(zone,
-                           translation_helper,
-                           data,
-                           data_program_offset),
+      : KernelReaderHelper(zone, translation_helper, data, data_program_offset),
         current_script_id_(initial_script_index),
         record_for_script_id_(record_for_script_id),
         record_token_positions_into_(record_token_positions_into) {}
@@ -202,8 +199,8 @@
   return array_object.ptr();
 }
 
-static void CollectKernelDataTokenPositions(
-    const ExternalTypedData& kernel_data,
+static void CollectKernelLibraryTokenPositions(
+    const TypedDataView& kernel_data,
     const Script& script,
     intptr_t kernel_offset,
     intptr_t data_kernel_offset,
@@ -242,7 +239,7 @@
   Library& lib = Library::Handle(zone);
   Object& entry = Object::Handle(zone);
   Script& entry_script = Script::Handle(zone);
-  ExternalTypedData& data = ExternalTypedData::Handle(zone);
+  auto& data = TypedDataView::Handle(zone);
 
   auto& interesting_script = *this;
 
@@ -255,7 +252,7 @@
     DictionaryIterator it(lib);
     while (it.HasNext()) {
       entry = it.GetNext();
-      data = ExternalTypedData::null();
+      data = TypedDataView::null();
       if (entry.IsClass()) {
         const Class& klass = Class::Cast(entry);
         if (klass.script() == interesting_script.ptr()) {
@@ -274,11 +271,11 @@
             if (entry_script.ptr() != interesting_script.ptr()) {
               continue;
             }
-            data = temp_field.KernelData();
-            CollectKernelDataTokenPositions(
-                data, interesting_script, temp_field.kernel_offset(),
-                temp_field.KernelDataProgramOffset(), zone, &helper,
-                &token_positions);
+            data = temp_field.KernelLibrary();
+            CollectKernelLibraryTokenPositions(data, interesting_script,
+                                               temp_field.kernel_offset(),
+                                               temp_field.KernelLibraryOffset(),
+                                               zone, &helper, &token_positions);
           }
           temp_array = klass.current_functions();
           for (intptr_t i = 0; i < temp_array.Length(); ++i) {
@@ -287,18 +284,18 @@
             if (entry_script.ptr() != interesting_script.ptr()) {
               continue;
             }
-            data = temp_function.KernelData();
-            CollectKernelDataTokenPositions(
+            data = temp_function.KernelLibrary();
+            CollectKernelLibraryTokenPositions(
                 data, interesting_script, temp_function.kernel_offset(),
-                temp_function.KernelDataProgramOffset(), zone, &helper,
+                temp_function.KernelLibraryOffset(), zone, &helper,
                 &token_positions);
           }
         } else {
           // Class isn't finalized yet: read the data attached to it.
           ASSERT(klass.kernel_offset() > 0);
-          data = lib.kernel_data();
+          data = lib.KernelLibrary();
           ASSERT(!data.IsNull());
-          const intptr_t library_kernel_offset = lib.kernel_offset();
+          const intptr_t library_kernel_offset = lib.KernelLibraryOffset();
           ASSERT(library_kernel_offset > 0);
           const intptr_t class_offset = klass.kernel_offset();
 
@@ -306,9 +303,9 @@
           if (entry_script.ptr() != interesting_script.ptr()) {
             continue;
           }
-          CollectKernelDataTokenPositions(data, interesting_script,
-                                          class_offset, library_kernel_offset,
-                                          zone, &helper, &token_positions);
+          CollectKernelLibraryTokenPositions(
+              data, interesting_script, class_offset, library_kernel_offset,
+              zone, &helper, &token_positions);
         }
       } else if (entry.IsFunction()) {
         temp_function ^= entry.ptr();
@@ -316,11 +313,11 @@
         if (entry_script.ptr() != interesting_script.ptr()) {
           continue;
         }
-        data = temp_function.KernelData();
-        CollectKernelDataTokenPositions(data, interesting_script,
-                                        temp_function.kernel_offset(),
-                                        temp_function.KernelDataProgramOffset(),
-                                        zone, &helper, &token_positions);
+        data = temp_function.KernelLibrary();
+        CollectKernelLibraryTokenPositions(data, interesting_script,
+                                           temp_function.kernel_offset(),
+                                           temp_function.KernelLibraryOffset(),
+                                           zone, &helper, &token_positions);
       } else if (entry.IsField()) {
         const Field& field = Field::Cast(entry);
         if (field.kernel_offset() <= 0) {
@@ -331,10 +328,10 @@
         if (entry_script.ptr() != interesting_script.ptr()) {
           continue;
         }
-        data = field.KernelData();
-        CollectKernelDataTokenPositions(
+        data = field.KernelLibrary();
+        CollectKernelLibraryTokenPositions(
             data, interesting_script, field.kernel_offset(),
-            field.KernelDataProgramOffset(), zone, &helper, &token_positions);
+            field.KernelLibraryOffset(), zone, &helper, &token_positions);
       }
     }
   }
@@ -357,8 +354,8 @@
       KernelProgramInfo::Handle(zone, kernel_program_info());
   helper.InitFromKernelProgramInfo(kernel_info);
 
-  ExternalTypedData& data =
-      ExternalTypedData::Handle(zone, interesting_script.constant_coverage());
+  const auto& data =
+      TypedDataView::Handle(zone, interesting_script.constant_coverage());
 
   kernel::KernelReaderHelper kernel_reader(zone, &helper, data, 0);
 
@@ -399,8 +396,8 @@
     ActiveClassScope active_class_scope(&active_class, &owner_class);
 
     KernelReaderHelper kernel_reader(
-        zone, &helper, ExternalTypedData::Handle(zone, field.KernelData()),
-        field.KernelDataProgramOffset());
+        zone, &helper, TypedDataView::Handle(zone, field.KernelLibrary()),
+        field.KernelLibraryOffset());
     kernel_reader.SetOffset(field.kernel_offset());
     ConstantReader constant_reader(&kernel_reader, &active_class);
 
@@ -418,13 +415,10 @@
  public:
   MetadataEvaluator(Zone* zone,
                     TranslationHelper* translation_helper,
-                    const ExternalTypedData& data,
+                    const TypedDataView& data,
                     intptr_t data_program_offset,
                     ActiveClass* active_class)
-      : KernelReaderHelper(zone,
-                           translation_helper,
-                           data,
-                           data_program_offset),
+      : KernelReaderHelper(zone, translation_helper, data, data_program_offset),
         constant_reader_(this, active_class) {}
 
   ObjectPtr EvaluateMetadata(intptr_t kernel_offset,
@@ -488,8 +482,8 @@
     ActiveClassScope active_class_scope(&active_class, &owner_class);
 
     MetadataEvaluator metadata_evaluator(
-        zone, &helper, ExternalTypedData::Handle(zone, library.kernel_data()),
-        library.kernel_offset(), &active_class);
+        zone, &helper, TypedDataView::Handle(zone, library.KernelLibrary()),
+        library.KernelLibraryOffset(), &active_class);
 
     return metadata_evaluator.EvaluateMetadata(kernel_offset,
                                                is_annotations_offset);
@@ -503,13 +497,10 @@
  public:
   ParameterDescriptorBuilder(TranslationHelper* translation_helper,
                              Zone* zone,
-                             const ExternalTypedData& data,
+                             const TypedDataView& data,
                              intptr_t data_program_offset,
                              ActiveClass* active_class)
-      : KernelReaderHelper(zone,
-                           translation_helper,
-                           data,
-                           data_program_offset),
+      : KernelReaderHelper(zone, translation_helper, data, data_program_offset),
         constant_reader_(this, active_class) {}
 
   ObjectPtr BuildParameterDescriptor(const Function& function);
@@ -597,8 +588,8 @@
     ActiveClassScope active_class_scope(&active_class, &owner_class);
 
     ParameterDescriptorBuilder builder(
-        &helper, zone, ExternalTypedData::Handle(zone, function.KernelData()),
-        function.KernelDataProgramOffset(), &active_class);
+        &helper, zone, TypedDataView::Handle(zone, function.KernelLibrary()),
+        function.KernelLibraryOffset(), &active_class);
 
     return builder.BuildParameterDescriptor(function);
   } else {
@@ -624,8 +615,8 @@
 
   KernelReaderHelper reader_helper(
       zone, &translation_helper,
-      ExternalTypedData::Handle(zone, function.KernelData()),
-      function.KernelDataProgramOffset());
+      TypedDataView::Handle(zone, function.KernelLibrary()),
+      function.KernelLibraryOffset());
 
   reader_helper.SetOffset(function.kernel_offset());
   reader_helper.ReadUntilFunctionNode();
@@ -746,7 +737,7 @@
 static ProcedureAttributesMetadata ProcedureAttributesOf(
     Zone* zone,
     const KernelProgramInfo& kernel_program_info,
-    const ExternalTypedData& kernel_data,
+    const TypedDataView& kernel_data,
     intptr_t kernel_data_program_offset,
     intptr_t kernel_offset) {
   TranslationHelper translation_helper(Thread::Current());
@@ -767,8 +758,8 @@
       KernelProgramInfo::Handle(zone, function.KernelProgramInfo());
   return ProcedureAttributesOf(
       zone, kernel_program_info,
-      ExternalTypedData::Handle(zone, function.KernelData()),
-      function.KernelDataProgramOffset(), function.kernel_offset());
+      TypedDataView::Handle(zone, function.KernelLibrary()),
+      function.KernelLibraryOffset(), function.kernel_offset());
 }
 
 ProcedureAttributesMetadata ProcedureAttributesOf(const Field& field,
@@ -777,14 +768,14 @@
       KernelProgramInfo::Handle(zone, field.KernelProgramInfo());
   return ProcedureAttributesOf(
       zone, kernel_program_info,
-      ExternalTypedData::Handle(zone, field.KernelData()),
-      field.KernelDataProgramOffset(), field.kernel_offset());
+      TypedDataView::Handle(zone, field.KernelLibrary()),
+      field.KernelLibraryOffset(), field.kernel_offset());
 }
 
 static UnboxingInfoMetadata* UnboxingInfoMetadataOf(
     Zone* zone,
     const KernelProgramInfo& kernel_program_info,
-    const ExternalTypedData& kernel_data,
+    const TypedDataView& kernel_data,
     intptr_t kernel_data_program_offset,
     intptr_t kernel_offset) {
   TranslationHelper translation_helper(Thread::Current());
@@ -801,8 +792,8 @@
       KernelProgramInfo::Handle(zone, function.KernelProgramInfo());
   return UnboxingInfoMetadataOf(
       zone, kernel_program_info,
-      ExternalTypedData::Handle(zone, function.KernelData()),
-      function.KernelDataProgramOffset(), function.kernel_offset());
+      TypedDataView::Handle(zone, function.KernelLibrary()),
+      function.KernelLibraryOffset(), function.kernel_offset());
 }
 
 TableSelectorMetadata* TableSelectorMetadataForProgram(
@@ -810,7 +801,7 @@
     Zone* zone) {
   TranslationHelper translation_helper(Thread::Current());
   translation_helper.InitFromKernelProgramInfo(info);
-  const auto& data = ExternalTypedData::Handle(zone, info.metadata_payloads());
+  const auto& data = TypedDataView::Handle(zone, info.metadata_payloads());
   KernelReaderHelper reader_helper(zone, &translation_helper, data, 0);
   TableSelectorMetadataHelper table_selector_metadata_helper(&reader_helper);
   return table_selector_metadata_helper.GetTableSelectorMetadata(zone);
diff --git a/runtime/vm/kernel.h b/runtime/vm/kernel.h
index d87a20f..e0b7468 100644
--- a/runtime/vm/kernel.h
+++ b/runtime/vm/kernel.h
@@ -59,18 +59,11 @@
 
 enum LogicalOperator { kAnd, kOr };
 
-struct ProgramBinary {
-  ProgramBinary SubView(intptr_t start, intptr_t end) const {
-    return {typed_data, kernel_data + start, end - start};
-  }
-
-  const ExternalTypedData* typed_data;
-  const uint8_t* kernel_data;
-  intptr_t kernel_data_size;
-};
-
 class Program {
  public:
+  static NNBDCompiledMode DetectNullSafety(const uint8_t* buffer,
+                                           intptr_t buffer_length);
+
   // Read a kernel Program from the given Reader. Note the returned Program
   // can potentially contain several "sub programs", though the library count
   // etc will reference the last "sub program" only.
@@ -101,13 +94,11 @@
   intptr_t library_count() { return library_count_; }
   NNBDCompiledMode compilation_mode() const { return compilation_mode_; }
 
-  const ProgramBinary& binary() const { return binary_; }
-  const ExternalTypedData* typed_data() { return binary().typed_data; }
-  const uint8_t* kernel_data() { return binary().kernel_data; }
-  intptr_t kernel_data_size() { return binary().kernel_data_size; }
+  // The data of the kernel file (single or multiple encoded components).
+  const TypedDataBase& binary() { return *binary_; }
 
  private:
-  Program() : binary_() {}
+  explicit Program(const TypedDataBase* binary) : binary_(binary) {}
 
   bool single_program_;
   NameIndex main_method_reference_;  // Procedure.
@@ -135,7 +126,7 @@
   // The offset from the start of the binary to the start of the string table.
   intptr_t string_table_offset_;
 
-  ProgramBinary binary_;
+  const TypedDataBase* binary_ = nullptr;
 
   DISALLOW_COPY_AND_ASSIGN(Program);
 };
diff --git a/runtime/vm/kernel_binary.cc b/runtime/vm/kernel_binary.cc
index 48b9c9f..78729b2 100644
--- a/runtime/vm/kernel_binary.cc
+++ b/runtime/vm/kernel_binary.cc
@@ -76,6 +76,23 @@
 const int kSdkHashSizeInBytes = 10;
 const char* kSdkHashNull = "0000000000";
 
+bool IsValidSdkHash(const uint8_t* sdk_hash) {
+  if (memcmp(Version::SdkHash(), kSdkHashNull, kSdkHashSizeInBytes) != 0 &&
+      memcmp(sdk_hash, kSdkHashNull, kSdkHashSizeInBytes) != 0 &&
+      memcmp(sdk_hash, Version::SdkHash(), kSdkHashSizeInBytes) != 0) {
+    return false;
+  }
+  return true;
+}
+
+NNBDCompiledMode Program::DetectNullSafety(const uint8_t* buffer,
+                                           intptr_t buffer_length) {
+  Reader reader(buffer, buffer_length);
+  std::unique_ptr<Program> program = Program::ReadFrom(&reader, nullptr);
+  if (program == nullptr) return NNBDCompiledMode::kInvalid;
+  return program->compilation_mode_;
+}
+
 std::unique_ptr<Program> Program::ReadFrom(Reader* reader, const char** error) {
   if (reader->size() < 70) {
     // A kernel file (v43) currently contains at least the following:
@@ -115,22 +132,15 @@
     return nullptr;
   }
 
-  uint8_t sdkHash[kSdkHashSizeInBytes + 1];
-  reader->ReadBytes(sdkHash, kSdkHashSizeInBytes);
-  sdkHash[kSdkHashSizeInBytes] = 0;  // Null terminate.
-  if (strcmp(Version::SdkHash(), kSdkHashNull) != 0 &&
-      strcmp((const char*)sdkHash, kSdkHashNull) != 0 &&
-      strcmp((const char*)sdkHash, Version::SdkHash()) != 0) {
+  if (!IsValidSdkHash(reader->BufferAt(reader->offset()))) {
     if (error != nullptr) {
       *error = kKernelInvalidSdkHash;
     }
     return nullptr;
   }
+  reader->set_offset(reader->offset() + kSdkHashSizeInBytes);
 
-  std::unique_ptr<Program> program(new Program());
-  program->binary_.typed_data = reader->typed_data();
-  program->binary_.kernel_data = reader->buffer();
-  program->binary_.kernel_data_size = reader->size();
+  std::unique_ptr<Program> program(new Program(reader->typed_data()));
 
   // Dill files can be concatenated (e.g. cat a.dill b.dill > c.dill). Find out
   // if this dill contains more than one program.
@@ -195,8 +205,7 @@
   const Object& ret = Object::Handle(isolate_group->CallTagHandler(
       Dart_kKernelTag, Object::null_object(), uri));
   if (ret.IsExternalTypedData()) {
-    const auto& typed_data = ExternalTypedData::Handle(
-        thread->zone(), ExternalTypedData::RawCast(ret.ptr()));
+    const auto& typed_data = ExternalTypedData::Cast(ret);
     kernel_program = kernel::Program::ReadFromTypedData(typed_data);
     return kernel_program;
   } else if (error != nullptr) {
@@ -213,7 +222,12 @@
 std::unique_ptr<Program> Program::ReadFromBuffer(const uint8_t* buffer,
                                                  intptr_t buffer_length,
                                                  const char** error) {
-  kernel::Reader reader(buffer, buffer_length);
+  // Whoever called this method (e.g. embedder) has to ensure the buffer stays
+  // alive until the VM is done with the last usage (e.g. isolate shutdown).
+  const auto& binary = ExternalTypedData::Handle(ExternalTypedData::New(
+      kExternalTypedDataUint8ArrayCid, const_cast<uint8_t*>(buffer),
+      buffer_length, Heap::kNew));
+  kernel::Reader reader(binary);
   return kernel::Program::ReadFrom(&reader, error);
 }
 
diff --git a/runtime/vm/kernel_binary.h b/runtime/vm/kernel_binary.h
index 88146d8..c5fc526 100644
--- a/runtime/vm/kernel_binary.h
+++ b/runtime/vm/kernel_binary.h
@@ -275,19 +275,11 @@
 
 class Reader : public ValueObject {
  public:
-  explicit Reader(const ProgramBinary& binary)
-      : Reader(binary.kernel_data, binary.kernel_data_size) {
-    // Make sure to link any Program / KernelProgramInfo objects created
-    // from this reader back to originating typed data to keep it alive.
-    set_typed_data(binary.typed_data);
+  explicit Reader(const TypedDataBase& typed_data)
+      : thread_(Thread::Current()), typed_data_(&typed_data) {
+    Init();
   }
 
-  explicit Reader(const ExternalTypedData& typed_data)
-      : thread_(Thread::Current()),
-        raw_buffer_(nullptr),
-        typed_data_(&typed_data),
-        size_(typed_data.IsNull() ? 0 : typed_data.Length()) {}
-
   uint32_t ReadFromIndex(intptr_t end_offset,
                          intptr_t fields_before,
                          intptr_t list_size,
@@ -295,19 +287,14 @@
     intptr_t org_offset = offset();
     uint32_t result =
         ReadFromIndexNoReset(end_offset, fields_before, list_size, list_index);
-    set_offset(org_offset);
+    offset_ = org_offset;
     return result;
   }
 
   uint32_t ReadUInt32At(intptr_t offset) const {
     ASSERT((size_ >= 4) && (offset >= 0) && (offset <= size_ - 4));
-    uint32_t value;
-    if (raw_buffer_ != nullptr) {
-      value = LoadUnaligned(
-          reinterpret_cast<const uint32_t*>(raw_buffer_ + offset));
-    } else {
-      value = typed_data_->GetUint32(offset);
-    }
+    uint32_t value =
+        LoadUnaligned(reinterpret_cast<const uint32_t*>(raw_buffer_ + offset));
     return Utils::BigEndianToHost32(value);
   }
 
@@ -315,7 +302,7 @@
                                 intptr_t fields_before,
                                 intptr_t list_size,
                                 intptr_t list_index) {
-    set_offset(end_offset - (fields_before + list_size - list_index) * 4);
+    offset_ = end_offset - (fields_before + list_size - list_index) * 4;
     return ReadUInt32();
   }
 
@@ -327,8 +314,8 @@
 
   double ReadDouble() {
     ASSERT((size_ >= 8) && (offset_ >= 0) && (offset_ <= size_ - 8));
-    double value = LoadUnaligned(
-        reinterpret_cast<const double*>(&this->buffer()[offset_]));
+    double value =
+        LoadUnaligned(reinterpret_cast<const double*>(&raw_buffer_[offset_]));
     offset_ += 8;
     return value;
   }
@@ -336,7 +323,7 @@
   uint32_t ReadUInt() {
     ASSERT((size_ >= 1) && (offset_ >= 0) && (offset_ <= size_ - 1));
 
-    const uint8_t* buffer = this->buffer();
+    const uint8_t* buffer = raw_buffer_;
     uint8_t byte0 = buffer[offset_];
     if ((byte0 & 0x80) == 0) {
       // 0...
@@ -359,14 +346,14 @@
   }
 
   intptr_t ReadSLEB128() {
-    ReadStream stream(this->buffer(), size_, offset_);
+    ReadStream stream(raw_buffer_, size_, offset_);
     const intptr_t result = stream.ReadSLEB128();
     offset_ = stream.Position();
     return result;
   }
 
   int64_t ReadSLEB128AsInt64() {
-    ReadStream stream(this->buffer(), size_, offset_);
+    ReadStream stream(raw_buffer_, size_, offset_);
     const int64_t result = stream.ReadSLEB128<int64_t>();
     offset_ = stream.Position();
     return result;
@@ -387,9 +374,9 @@
 
   intptr_t ReadListLength() { return ReadUInt(); }
 
-  uint8_t ReadByte() { return buffer()[offset_++]; }
+  uint8_t ReadByte() { return raw_buffer_[offset_++]; }
 
-  uint8_t PeekByte() { return buffer()[offset_]; }
+  uint8_t PeekByte() { return raw_buffer_[offset_]; }
 
   void ReadBytes(uint8_t* buffer, uint8_t size) {
     for (int i = 0; i < size; i++) {
@@ -476,52 +463,52 @@
   // the root name as in the canonical name table.
   NameIndex ReadCanonicalNameReference() { return NameIndex(ReadUInt() - 1); }
 
+  const TypedDataBase* typed_data() { return typed_data_; }
+
   intptr_t offset() const { return offset_; }
-  void set_offset(intptr_t offset) { offset_ = offset; }
-
-  intptr_t size() const { return size_; }
-  void set_size(intptr_t size) { size_ = size; }
-
-  const ExternalTypedData* typed_data() const { return typed_data_; }
-  void set_typed_data(const ExternalTypedData* typed_data) {
-    typed_data_ = typed_data;
+  void set_offset(intptr_t offset) {
+    ASSERT(offset < size_);
+    offset_ = offset;
   }
+  intptr_t size() const { return size_; }
 
-  const uint8_t* raw_buffer() const { return raw_buffer_; }
-  void set_raw_buffer(const uint8_t* raw_buffer) { raw_buffer_ = raw_buffer; }
-
-  ExternalTypedDataPtr ExternalDataFromTo(intptr_t start, intptr_t end) {
-    return ExternalTypedData::New(kExternalTypedDataUint8ArrayCid,
-                                  const_cast<uint8_t*>(buffer() + start),
-                                  end - start, Heap::kOld);
+  TypedDataViewPtr ViewFromTo(intptr_t start, intptr_t end) {
+    return typed_data_->ViewFromTo(start, end, Heap::kOld);
   }
 
   const uint8_t* BufferAt(intptr_t offset) {
     ASSERT((offset >= 0) && (offset < size_));
-    return &buffer()[offset];
+    return &raw_buffer_[offset];
   }
 
   TypedDataPtr ReadLineStartsData(intptr_t line_start_count);
 
  private:
+  friend class Program;
+  friend class AlternativeReadingScopeWithNewData;
+  friend class AlternativeReadingScope;
+
   Reader(const uint8_t* buffer, intptr_t size)
       : thread_(nullptr),
         raw_buffer_(buffer),
-        typed_data_(nullptr),
         size_(size) {}
 
-  const uint8_t* buffer() const {
-    if (raw_buffer_ != nullptr) {
-      return raw_buffer_;
-    }
-    NoSafepointScope no_safepoint(thread_);
-    return reinterpret_cast<uint8_t*>(typed_data_->DataAddr(0));
+  void Init() {
+    ASSERT(typed_data_->IsExternalOrExternalView());
+    raw_buffer_ = reinterpret_cast<uint8_t*>(typed_data_->DataAddr(0));
+    size_ = typed_data_->LengthInBytes();
+    offset_ = 0;
   }
 
-  Thread* thread_;
-  const uint8_t* raw_buffer_;
-  const ExternalTypedData* typed_data_;
-  intptr_t size_;
+  Thread* thread_ = nullptr;
+
+  // A external typed data or a view on an external typed data.
+  const TypedDataBase* typed_data_ = nullptr;
+
+  // The raw data size/length of [typed_data_].
+  const uint8_t* raw_buffer_ = nullptr;
+  intptr_t size_ = 0;
+
   intptr_t offset_ = 0;
   TokenPosition max_position_ = TokenPosition::kNoSource;
   TokenPosition min_position_ = TokenPosition::kNoSource;
@@ -536,14 +523,14 @@
 class AlternativeReadingScope {
  public:
   AlternativeReadingScope(Reader* reader, intptr_t new_position)
-      : reader_(reader), saved_offset_(reader_->offset()) {
-    reader_->set_offset(new_position);
+      : reader_(reader), saved_offset_(reader_->offset_) {
+    reader_->offset_ = new_position;
   }
 
   explicit AlternativeReadingScope(Reader* reader)
-      : reader_(reader), saved_offset_(reader_->offset()) {}
+      : reader_(reader), saved_offset_(reader_->offset_) {}
 
-  ~AlternativeReadingScope() { reader_->set_offset(saved_offset_); }
+  ~AlternativeReadingScope() { reader_->offset_ = saved_offset_; }
 
   intptr_t saved_offset() { return saved_offset_; }
 
@@ -559,24 +546,23 @@
 class AlternativeReadingScopeWithNewData {
  public:
   AlternativeReadingScopeWithNewData(Reader* reader,
-                                     const ExternalTypedData* new_typed_data,
+                                     const TypedDataBase* new_typed_data,
                                      intptr_t new_position)
       : reader_(reader),
-        saved_size_(reader_->size()),
-        saved_raw_buffer_(reader_->raw_buffer()),
-        saved_typed_data_(reader_->typed_data()),
-        saved_offset_(reader_->offset()) {
-    reader_->set_raw_buffer(nullptr);
-    reader_->set_typed_data(new_typed_data);
-    reader_->set_size(new_typed_data->Length());
-    reader_->set_offset(new_position);
+        saved_size_(reader_->size_),
+        saved_raw_buffer_(reader_->raw_buffer_),
+        saved_typed_data_(reader_->typed_data_),
+        saved_offset_(reader_->offset_) {
+    reader_->typed_data_ = new_typed_data;
+    reader_->Init();
+    reader_->offset_ = new_position;
   }
 
   ~AlternativeReadingScopeWithNewData() {
-    reader_->set_raw_buffer(saved_raw_buffer_);
-    reader_->set_typed_data(saved_typed_data_);
-    reader_->set_size(saved_size_);
-    reader_->set_offset(saved_offset_);
+    reader_->raw_buffer_ = saved_raw_buffer_;
+    reader_->typed_data_ = saved_typed_data_;
+    reader_->size_ = saved_size_;
+    reader_->offset_ = saved_offset_;
   }
 
   intptr_t saved_offset() { return saved_offset_; }
@@ -585,7 +571,7 @@
   Reader* reader_;
   intptr_t saved_size_;
   const uint8_t* saved_raw_buffer_;
-  const ExternalTypedData* saved_typed_data_;
+  const TypedDataBase* saved_typed_data_;
   intptr_t saved_offset_;
 
   DISALLOW_COPY_AND_ASSIGN(AlternativeReadingScopeWithNewData);
diff --git a/runtime/vm/kernel_loader.cc b/runtime/vm/kernel_loader.cc
index 3cc7cd7..df575ac 100644
--- a/runtime/vm/kernel_loader.cc
+++ b/runtime/vm/kernel_loader.cc
@@ -149,7 +149,7 @@
   return loader_->LookupClass(library_lookup_handle_, klass);
 }
 
-LibraryIndex::LibraryIndex(const ExternalTypedData& kernel_data)
+LibraryIndex::LibraryIndex(const TypedDataView& kernel_data)
     : reader_(kernel_data) {
   intptr_t data_size = reader_.size();
 
@@ -163,14 +163,7 @@
   source_references_offset_ = reader_.ReadUInt32At(class_index_offset_ - 4);
 }
 
-ClassIndex::ClassIndex(const ProgramBinary& binary,
-                       intptr_t class_offset,
-                       intptr_t class_size)
-    : reader_(binary) {
-  Init(class_offset, class_size);
-}
-
-ClassIndex::ClassIndex(const ExternalTypedData& library_kernel_data,
+ClassIndex::ClassIndex(const TypedDataBase& library_kernel_data,
                        intptr_t class_offset,
                        intptr_t class_size)
     : reader_(library_kernel_data) {
@@ -196,7 +189,7 @@
       library_kernel_offset_(-1),  // Set to the correct value in LoadLibrary
       correction_offset_(-1),      // Set to the correct value in LoadLibrary
       loading_native_wrappers_library_(false),
-      library_kernel_data_(ExternalTypedData::ZoneHandle(zone_)),
+      library_kernel_data_(TypedDataView::ZoneHandle(zone_)),
       kernel_program_info_(KernelProgramInfo::ZoneHandle(zone_)),
       translation_helper_(this, thread_, Heap::kOld),
       helper_(zone_,
@@ -244,9 +237,11 @@
     return Object::Handle(loader.LoadProgram(process_pending_classes));
   }
 
-  kernel::Reader reader(program->binary());
   GrowableArray<intptr_t> subprogram_file_starts;
-  index_programs(&reader, &subprogram_file_starts);
+  {
+    kernel::Reader reader(program->binary());
+    index_programs(&reader, &subprogram_file_starts);
+  }
 
   Zone* zone = thread->zone();
   Library& library = Library::Handle(zone);
@@ -255,15 +250,15 @@
   // First index all source tables.
   UriToSourceTable uri_to_source_table;
   UriToSourceTableEntry wrapper;
+  Thread* thread_ = Thread::Current();
+  Zone* zone_ = thread_->zone();
   for (intptr_t i = subprogram_count - 1; i >= 0; --i) {
     intptr_t subprogram_start = subprogram_file_starts.At(i);
     intptr_t subprogram_end = subprogram_file_starts.At(i + 1);
-    Thread* thread_ = Thread::Current();
-    Zone* zone_ = thread_->zone();
+    const auto& component = TypedDataBase::Handle(
+        program->binary().ViewFromTo(subprogram_start, subprogram_end));
     TranslationHelper translation_helper(thread);
-    KernelReaderHelper helper_(
-        zone_, &translation_helper,
-        program->binary().SubView(subprogram_start, subprogram_end), 0);  // ,
+    KernelReaderHelper helper_(zone_, &translation_helper, component, 0);
     const intptr_t source_table_size = helper_.SourceTableSize();
     for (intptr_t index = 0; index < source_table_size; ++index) {
       const String& uri_string = helper_.SourceTableUriFor(index);
@@ -305,9 +300,9 @@
   for (intptr_t i = subprogram_count - 1; i >= 0; --i) {
     intptr_t subprogram_start = subprogram_file_starts.At(i);
     intptr_t subprogram_end = subprogram_file_starts.At(i + 1);
-    reader.set_raw_buffer(program->kernel_data() + subprogram_start);
-    reader.set_size(subprogram_end - subprogram_start);
-    reader.set_offset(0);
+    const auto& component = TypedDataBase::Handle(
+        program->binary().ViewFromTo(subprogram_start, subprogram_end));
+    Reader reader(component);
     const char* error = nullptr;
     std::unique_ptr<Program> subprogram = Program::ReadFrom(&reader, &error);
     if (subprogram == nullptr) {
@@ -355,13 +350,13 @@
 StringPtr KernelLoader::FindSourceForScript(const uint8_t* kernel_buffer,
                                             intptr_t kernel_buffer_length,
                                             const String& uri) {
+  const auto& binary = ExternalTypedData::Handle(ExternalTypedData::New(
+      kExternalTypedDataUint8ArrayCid, const_cast<uint8_t*>(kernel_buffer),
+      kernel_buffer_length, Heap::kNew));
+
   Thread* thread = Thread::Current();
   Zone* zone = thread->zone();
   TranslationHelper translation_helper(thread);
-  // Note: it is okay to have typed_data be nullptr here because we are not
-  // creating any long living views into the kernel_buffer.
-  const ProgramBinary binary = {/*typed_data=*/nullptr, kernel_buffer,
-                                kernel_buffer_length};
   KernelReaderHelper reader(zone, &translation_helper, binary, 0);
   intptr_t source_table_size = reader.SourceTableSize();
   for (intptr_t i = 0; i < source_table_size; ++i) {
@@ -378,12 +373,14 @@
   const Array& scripts =
       Array::Handle(Z, Array::New(source_table_size, Heap::kOld));
 
+  const auto& binary = program_->binary();
+
   // Copy the Kernel string offsets out of the binary and into the VM's heap.
   ASSERT(program_->string_table_offset() >= 0);
-  Reader reader(program_->binary());
+  Reader reader(binary);
   reader.set_offset(program_->string_table_offset());
   intptr_t count = reader.ReadUInt() + 1;
-  TypedData& offsets = TypedData::Handle(
+  const auto& offsets = TypedData::Handle(
       Z, TypedData::New(kTypedDataUint32ArrayCid, count, Heap::kOld));
   offsets.SetUint32(0, 0);
   intptr_t end_offset = 0;
@@ -393,15 +390,12 @@
   }
 
   // Create view of the string data.
-  const ExternalTypedData& data = ExternalTypedData::Handle(
-      Z,
-      reader.ExternalDataFromTo(reader.offset(), reader.offset() + end_offset));
+  const auto& string_data = TypedDataView::Handle(
+      reader.ViewFromTo(reader.offset(), reader.offset() + end_offset));
 
-  // Create a view of the constants table (first part)
-  // and the constant table index (second part).
-  const ExternalTypedData& constants_table = ExternalTypedData::Handle(
-      Z, reader.ExternalDataFromTo(program_->constant_table_offset(),
-                                   program_->name_table_offset()));
+  // Create a view of the constants table.
+  const auto& constants_table = TypedDataView::Handle(reader.ViewFromTo(
+      program_->constant_table_offset(), program_->name_table_offset()));
 
   // Copy the canonical names into the VM's heap.  Encode them as unsigned, so
   // the parent indexes are adjusted when extracted.
@@ -414,15 +408,15 @@
   }
 
   // Create view of metadata payloads.
-  const ExternalTypedData& metadata_payloads = ExternalTypedData::Handle(
-      Z, reader.ExternalDataFromTo(program_->metadata_payloads_offset(),
-                                   program_->metadata_mappings_offset()));
+  const auto& metadata_payloads = TypedDataView::Handle(
+      reader.ViewFromTo(program_->metadata_payloads_offset(),
+                        program_->metadata_mappings_offset()));
+
   ASSERT(Utils::IsAligned(metadata_payloads.DataAddr(0), kWordSize));
 
   // Create view of metadata mappings.
-  const ExternalTypedData& metadata_mappings = ExternalTypedData::Handle(
-      Z, reader.ExternalDataFromTo(program_->metadata_mappings_offset(),
-                                   program_->string_table_offset()));
+  const auto& metadata_mappings = TypedDataView::Handle(reader.ViewFromTo(
+      program_->metadata_mappings_offset(), program_->string_table_offset()));
 
 #if defined(DEBUG)
   MetadataHelper::VerifyMetadataMappings(metadata_mappings);
@@ -438,10 +432,8 @@
              kClassesPerLibraryGuess * program_->library_count(), Heap::kOld));
 
   kernel_program_info_ = KernelProgramInfo::New(
-      offsets, data, names, metadata_payloads, metadata_mappings,
-      constants_table, scripts, libraries_cache, classes_cache,
-      program_->typed_data() == nullptr ? Object::null_object()
-                                        : *program_->typed_data());
+      binary, string_data, metadata_payloads, metadata_mappings,
+      constants_table, offsets, names, scripts, libraries_cache, classes_cache);
 
   H.InitFromKernelProgramInfo(kernel_program_info_);
 
@@ -453,7 +445,7 @@
 }
 
 KernelLoader::KernelLoader(const KernelProgramInfo& kernel_program_info,
-                           const ExternalTypedData& kernel_data,
+                           const TypedDataBase& kernel_data,
                            intptr_t data_program_offset)
     : program_(nullptr),
       thread_(Thread::Current()),
@@ -463,7 +455,7 @@
       library_kernel_offset_(data_program_offset),
       correction_offset_(0),
       loading_native_wrappers_library_(false),
-      library_kernel_data_(ExternalTypedData::ZoneHandle(zone_)),
+      library_kernel_data_(TypedDataView::ZoneHandle(zone_)),
       kernel_program_info_(
           KernelProgramInfo::ZoneHandle(zone_, kernel_program_info.ptr())),
       translation_helper_(this, thread_, Heap::kOld),
@@ -482,7 +474,6 @@
       expression_evaluation_library_(Library::Handle(Z)) {
   ASSERT(T.active_class_ == &active_class_);
   T.finalize_ = false;
-  library_kernel_data_ = kernel_data.ptr();
   H.InitFromKernelProgramInfo(kernel_program_info_);
 }
 
@@ -614,11 +605,9 @@
   // kernel data and parent.
   const auto& eval_script = Script::Handle(Z, function.script());
   ASSERT(!expression_evaluation_library_.IsNull());
-  auto& kernel_data = ExternalTypedData::Handle(
-      Z, expression_evaluation_library_.kernel_data());
-  intptr_t kernel_offset = expression_evaluation_library_.kernel_offset();
-  function.SetKernelDataAndEvalScript(eval_script, kernel_program_info_,
-                                      kernel_data, kernel_offset);
+  function.SetKernelLibraryAndEvalScript(
+      eval_script, kernel_program_info_,
+      expression_evaluation_library_.kernel_library_index());
 
   function.set_owner(real_class);
 
@@ -678,18 +667,21 @@
       loader.walk_incremental_kernel(modified_libs, is_empty_program,
                                      p_num_classes, p_num_procedures);
     }
-    kernel::Reader reader(program->binary());
+
     GrowableArray<intptr_t> subprogram_file_starts;
-    index_programs(&reader, &subprogram_file_starts);
+    {
+      kernel::Reader reader(program->binary());
+      index_programs(&reader, &subprogram_file_starts);
+    }
 
     // Create "fake programs" for each sub-program.
     intptr_t subprogram_count = subprogram_file_starts.length() - 1;
     for (intptr_t i = 0; i < subprogram_count; ++i) {
       intptr_t subprogram_start = subprogram_file_starts.At(i);
       intptr_t subprogram_end = subprogram_file_starts.At(i + 1);
-      reader.set_raw_buffer(program->kernel_data() + subprogram_start);
-      reader.set_size(subprogram_end - subprogram_start);
-      reader.set_offset(0);
+      const auto& component = TypedDataBase::Handle(
+          program->binary().ViewFromTo(subprogram_start, subprogram_end));
+      Reader reader(component);
       const char* error = nullptr;
       std::unique_ptr<Program> subprogram = Program::ReadFrom(&reader, &error);
       if (subprogram == nullptr) {
@@ -727,7 +719,7 @@
     if (collect_library_stats) {
       intptr_t library_end = library_offset(i + 1);
       library_kernel_data_ =
-          helper_.reader_.ExternalDataFromTo(kernel_offset, library_end);
+          helper_.reader_.ViewFromTo(kernel_offset, library_end);
       LibraryIndex library_index(library_kernel_data_);
       num_classes += library_index.class_count();
       num_procedures += library_index.procedure_count();
@@ -845,12 +837,16 @@
   }
   library.set_nnbd_compiled_mode(mode);
 
-  library_kernel_data_ = helper_.reader_.ExternalDataFromTo(
+  library_kernel_data_ = helper_.reader_.ViewFromTo(
       library_kernel_offset_, library_kernel_offset_ + library_size);
-  library.set_kernel_data(library_kernel_data_);
-  library.set_kernel_offset(library_kernel_offset_);
+  library.set_kernel_library_index(index);
   library.set_kernel_program_info(kernel_program_info_);
 
+  const intptr_t start_offset =
+      kernel_program_info_.KernelLibraryStartOffset(index);
+  const intptr_t end_offset =
+      kernel_program_info_.KernelLibraryEndOffset(index);
+  library_kernel_data_ = helper_.reader_.ViewFromTo(start_offset, end_offset);
   LibraryIndex library_index(library_kernel_data_);
   intptr_t class_count = library_index.class_count();
 
@@ -1685,17 +1681,18 @@
   Zone* zone = Thread::Current()->zone();
   const Library& library = Library::Handle(zone, klass.library());
   const Class& toplevel_class = Class::Handle(zone, library.toplevel_class());
-  const ExternalTypedData& library_kernel_data =
-      ExternalTypedData::Handle(zone, library.kernel_data());
+  const auto& library_kernel_data =
+      TypedDataView::Handle(zone, library.KernelLibrary());
   ASSERT(!library_kernel_data.IsNull());
-  const intptr_t library_kernel_offset = library.kernel_offset();
-  ASSERT(library_kernel_offset > 0);
 
-  auto& kernel_info =
+  const auto& kernel_info =
       KernelProgramInfo::Handle(zone, klass.KernelProgramInfo());
+  const intptr_t library_kernel_offset =
+      kernel_info.KernelLibraryStartOffset(library.kernel_library_index());
 
   KernelLoader kernel_loader(kernel_info, library_kernel_data,
                              library_kernel_offset);
+
   LibraryIndex library_index(library_kernel_data);
 
   if (klass.IsTopLevel()) {
@@ -1930,11 +1927,10 @@
     PatchClass& patch_class = PatchClass::ZoneHandle(Z);
     patch_class ^= patch_classes_.At(source_uri_index);
     if (patch_class.IsNull() || patch_class.wrapped_class() != klass.ptr()) {
-      ASSERT(!library_kernel_data_.IsNull());
+      const auto& lib = Library::Handle(klass.library());
       patch_class =
           PatchClass::New(klass, kernel_program_info_, correct_script);
-      patch_class.set_library_kernel_data(library_kernel_data_);
-      patch_class.set_library_kernel_offset(library_kernel_offset_);
+      patch_class.set_kernel_library_index(lib.kernel_library_index());
       patch_classes_.SetAt(source_uri_index, patch_class);
     }
     return patch_class;
@@ -1946,7 +1942,7 @@
                                      UriToSourceTable* uri_to_source_table) {
   const String& uri_string = helper_.SourceTableUriFor(index);
   const String& import_uri_string = helper_.SourceTableImportUriFor(index);
-  auto& constant_coverage = ExternalTypedData::Handle(Z);
+  auto& constant_coverage = TypedDataView::Handle(Z);
   NOT_IN_PRODUCT(constant_coverage = helper_.GetConstantCoverageFor(index));
 
   String& sources = String::Handle(Z);
@@ -2234,9 +2230,7 @@
   const PatchClass& initializer_owner = PatchClass::Handle(
       zone, PatchClass::New(field_owner, kernel_program_info, script));
   const Library& lib = Library::Handle(zone, field_owner.library());
-  initializer_owner.set_library_kernel_data(
-      ExternalTypedData::Handle(zone, lib.kernel_data()));
-  initializer_owner.set_library_kernel_offset(lib.kernel_offset());
+  initializer_owner.set_kernel_library_index(lib.kernel_library_index());
 
   // Create a static initializer.
   FunctionType& signature = FunctionType::Handle(zone, FunctionType::New());
diff --git a/runtime/vm/kernel_loader.h b/runtime/vm/kernel_loader.h
index f7a6630..4336f0a 100644
--- a/runtime/vm/kernel_loader.h
+++ b/runtime/vm/kernel_loader.h
@@ -83,8 +83,7 @@
 
 class LibraryIndex {
  public:
-  // |kernel_data| is the kernel data for one library alone.
-  explicit LibraryIndex(const ExternalTypedData& kernel_data);
+  explicit LibraryIndex(const TypedDataView& kernel_data);
 
   intptr_t class_count() const { return class_count_; }
   intptr_t procedure_count() const { return procedure_count_; }
@@ -123,15 +122,9 @@
 
 class ClassIndex {
  public:
-  // |class_offset| is the offset of class' kernel data in |buffer| of
-  // size |size|. The size of the class' kernel data is |class_size|.
-  ClassIndex(const ProgramBinary& binary,
-             intptr_t class_offset,
-             intptr_t class_size);
-
   // |class_offset| is the offset of class' kernel data in |kernel_data|.
   // The size of the class' kernel data is |class_size|.
-  ClassIndex(const ExternalTypedData& kernel_data,
+  ClassIndex(const TypedDataBase& kernel_data,
              intptr_t class_offset,
              intptr_t class_size);
 
@@ -234,7 +227,7 @@
                          bool* has_pragma_annotation);
 
   KernelLoader(const KernelProgramInfo& kernel_program_info,
-               const ExternalTypedData& kernel_data,
+               const TypedDataBase& kernel_data,
                intptr_t data_program_offset);
 
   void InitializeFields(
@@ -364,7 +357,7 @@
 
   NameIndex skip_vmservice_library_;
 
-  ExternalTypedData& library_kernel_data_;
+  TypedDataView& library_kernel_data_;
   KernelProgramInfo& kernel_program_info_;
   BuildingTranslationHelper translation_helper_;
   KernelReaderHelper helper_;
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 8bbf960..e9ac9a1 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -7833,7 +7833,7 @@
   NOT_IN_PRECOMPILED_RUNTIME(
       result.untag()->set_kernel_program_info(info.ptr()));
   result.set_script(script);
-  result.set_library_kernel_offset(-1);
+  result.set_kernel_library_index(-1);
   return result.ptr();
 }
 
@@ -7856,10 +7856,6 @@
   untag()->set_script(value.ptr());
 }
 
-void PatchClass::set_library_kernel_data(const ExternalTypedData& data) const {
-  untag()->set_library_kernel_data(data.ptr());
-}
-
 uword Function::Hash() const {
   uword hash = String::HashRawSymbol(name());
   if (IsClosureFunction()) {
@@ -8427,8 +8423,7 @@
 // This field is heavily overloaded:
 //   kernel eval function:    Array[0] = Script
 //                            Array[1] = KernelProgramInfo
-//                            Array[2] = Kernel data
-//                            Array[3] = Kernel offset of enclosing library
+//                            Array[2] = Kernel index of enclosing library
 //   method extractor:        Function extracted closure function
 //   implicit getter:         Field
 //   implicit setter:         Field
@@ -10664,19 +10659,17 @@
 #endif
 }
 
-void Function::SetKernelDataAndEvalScript(
+void Function::SetKernelLibraryAndEvalScript(
     const Script& script,
     const class KernelProgramInfo& kernel_program_info,
-    const ExternalTypedData& data,
-    intptr_t offset) const {
+    intptr_t index) const {
   Array& data_field = Array::Handle(
       Array::New(static_cast<intptr_t>(EvalFunctionData::kLength)));
   data_field.SetAt(static_cast<intptr_t>(EvalFunctionData::kScript), script);
   data_field.SetAt(static_cast<intptr_t>(EvalFunctionData::kKernelProgramInfo),
                    kernel_program_info);
-  data_field.SetAt(static_cast<intptr_t>(EvalFunctionData::kKernelData), data);
-  data_field.SetAt(static_cast<intptr_t>(EvalFunctionData::kKernelOffset),
-                   Smi::Handle(Smi::New(offset)));
+  data_field.SetAt(static_cast<intptr_t>(EvalFunctionData::kKernelLibraryIndex),
+                   Smi::Handle(Smi::New(index)));
   set_data(data_field);
 }
 
@@ -10734,51 +10727,44 @@
   }
   return PatchClass::Cast(owner).kernel_program_info();
 }
-#endif
 
-ExternalTypedDataPtr Function::KernelData() const {
-  if (is_eval_function()) {
-    const auto& fdata = Array::Handle(Array::RawCast(data()));
-    return ExternalTypedData::RawCast(
-        fdata.At(static_cast<intptr_t>(EvalFunctionData::kKernelData)));
-  }
-  if (IsClosureFunction()) {
-    Function& parent = Function::Handle(parent_function());
-    ASSERT(!parent.IsNull());
-    return parent.KernelData();
-  }
-
-  const auto& owner = Object::Handle(RawOwner());
-  if (owner.IsClass()) {
-    return Library::Handle(Class::Cast(owner).library()).kernel_data();
-  }
-  return PatchClass::Cast(owner).library_kernel_data();
+TypedDataViewPtr Function::KernelLibrary() const {
+  const auto& info = KernelProgramInfo::Handle(KernelProgramInfo());
+  return info.KernelLibrary(KernelLibraryIndex());
 }
 
-intptr_t Function::KernelDataProgramOffset() const {
+intptr_t Function::KernelLibraryOffset() const {
+  const intptr_t kernel_library_index = KernelLibraryIndex();
+  if (kernel_library_index == -1) return 0;
+  const auto& info = KernelProgramInfo::Handle(KernelProgramInfo());
+  return info.KernelLibraryStartOffset(kernel_library_index);
+}
+
+intptr_t Function::KernelLibraryIndex() const {
   if (IsNoSuchMethodDispatcher() || IsInvokeFieldDispatcher() ||
       IsFfiTrampoline()) {
-    return 0;
+    return -1;
   }
   if (is_eval_function()) {
     const auto& fdata = Array::Handle(Array::RawCast(data()));
-    return Smi::Value(static_cast<SmiPtr>(
-        fdata.At(static_cast<intptr_t>(EvalFunctionData::kKernelOffset))));
+    return Smi::Value(static_cast<SmiPtr>(fdata.At(
+        static_cast<intptr_t>(EvalFunctionData::kKernelLibraryIndex))));
   }
   if (IsClosureFunction()) {
-    Function& parent = Function::Handle(parent_function());
+    const auto& parent = Function::Handle(parent_function());
     ASSERT(!parent.IsNull());
-    return parent.KernelDataProgramOffset();
+    return parent.KernelLibraryIndex();
   }
 
-  const Object& obj = Object::Handle(untag()->owner());
+  const auto& obj = Object::Handle(untag()->owner());
   if (obj.IsClass()) {
-    Library& lib = Library::Handle(Class::Cast(obj).library());
-    return lib.kernel_offset();
+    const auto& lib = Library::Handle(Class::Cast(obj).library());
+    return lib.kernel_library_index();
   }
   ASSERT(obj.IsPatchClass());
-  return PatchClass::Cast(obj).library_kernel_offset();
+  return PatchClass::Cast(obj).kernel_library_index();
 }
+#endif
 
 bool Function::HasOptimizedCode() const {
   return HasCode() && Code::Handle(CurrentCode()).is_optimized();
@@ -11699,20 +11685,6 @@
   return String::HashRawSymbol(name());
 }
 
-ExternalTypedDataPtr Field::KernelData() const {
-  const Object& obj = Object::Handle(this->untag()->owner());
-  // During background JIT compilation field objects are copied
-  // and copy points to the original field via the owner field.
-  if (obj.IsField()) {
-    return Field::Cast(obj).KernelData();
-  } else if (obj.IsClass()) {
-    Library& library = Library::Handle(Class::Cast(obj).library());
-    return library.kernel_data();
-  }
-  ASSERT(obj.IsPatchClass());
-  return PatchClass::Cast(obj).library_kernel_data();
-}
-
 void Field::InheritKernelOffsetFrom(const Field& src) const {
 #if defined(DART_PRECOMPILED_RUNTIME)
   UNREACHABLE();
@@ -11721,19 +11693,33 @@
 #endif
 }
 
-intptr_t Field::KernelDataProgramOffset() const {
+#if !defined(DART_PRECOMPILED_RUNTIME)
+TypedDataViewPtr Field::KernelLibrary() const {
+  const auto& info = KernelProgramInfo::Handle(KernelProgramInfo());
+  return info.KernelLibrary(KernelLibraryIndex());
+}
+
+intptr_t Field::KernelLibraryOffset() const {
+  const intptr_t kernel_library_index = KernelLibraryIndex();
+  if (kernel_library_index == -1) return 0;
+  const auto& info = KernelProgramInfo::Handle(KernelProgramInfo());
+  return info.KernelLibraryStartOffset(kernel_library_index);
+}
+
+intptr_t Field::KernelLibraryIndex() const {
   const Object& obj = Object::Handle(untag()->owner());
   // During background JIT compilation field objects are copied
   // and copy points to the original field via the owner field.
   if (obj.IsField()) {
-    return Field::Cast(obj).KernelDataProgramOffset();
+    return Field::Cast(obj).KernelLibraryIndex();
   } else if (obj.IsClass()) {
-    Library& lib = Library::Handle(Class::Cast(obj).library());
-    return lib.kernel_offset();
+    const auto& lib = Library::Handle(Class::Cast(obj).library());
+    return lib.kernel_library_index();
   }
   ASSERT(obj.IsPatchClass());
-  return PatchClass::Cast(obj).library_kernel_offset();
+  return PatchClass::Cast(obj).kernel_library_index();
 }
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
 void Field::SetFieldTypeSafe(const AbstractType& value) const {
   ASSERT(IsOriginal());
@@ -12917,7 +12903,7 @@
     const KernelProgramInfo& info,
     intptr_t script_index,
     const TypedData& line_starts,
-    const ExternalTypedData& constant_coverage) const {
+    const TypedDataView& constant_coverage) const {
   StoreNonPointer(&untag()->kernel_script_index_, script_index);
   untag()->set_kernel_program_info(info.ptr());
   untag()->set_line_starts(line_starts.ptr());
@@ -13010,7 +12996,7 @@
 }
 
 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
-ExternalTypedDataPtr Script::constant_coverage() const {
+TypedDataViewPtr Script::constant_coverage() const {
   return untag()->constant_coverage();
 }
 #endif  // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
@@ -13401,12 +13387,18 @@
 void Library::set_kernel_program_info(const KernelProgramInfo& info) const {
   untag()->set_kernel_program_info(info.ptr());
 }
-#endif
 
-void Library::set_kernel_data(const ExternalTypedData& data) const {
-  untag()->set_kernel_data(data.ptr());
+TypedDataViewPtr Library::KernelLibrary() const {
+  const auto& info = KernelProgramInfo::Handle(kernel_program_info());
+  return info.KernelLibrary(kernel_library_index());
 }
 
+intptr_t Library::KernelLibraryOffset() const {
+  const auto& info = KernelProgramInfo::Handle(kernel_program_info());
+  return info.KernelLibraryStartOffset(kernel_library_index());
+}
+#endif
+
 void Library::set_loading_unit(const LoadingUnit& value) const {
   untag()->set_loading_unit(value.ptr());
 }
@@ -14342,7 +14334,8 @@
     result.set_debuggable(true);
   }
   result.set_is_dart_scheme(dart_scheme);
-  NOT_IN_PRECOMPILED(result.set_kernel_offset(0));
+  NOT_IN_PRECOMPILED(
+      result.StoreNonPointer(&result.untag()->kernel_library_index_, -1));
   result.StoreNonPointer(&result.untag()->load_state_,
                          UntaggedLibrary::kAllocated);
   result.StoreNonPointer(&result.untag()->index_, -1);
@@ -15180,18 +15173,24 @@
 }
 
 KernelProgramInfoPtr KernelProgramInfo::New(
+    const TypedDataBase& kernel_component,
+    const TypedDataView& string_data,
+    const TypedDataView& metadata_payloads,
+    const TypedDataView& metadata_mappings,
+    const TypedDataView& constants_table,
     const TypedData& string_offsets,
-    const ExternalTypedData& string_data,
     const TypedData& canonical_names,
-    const ExternalTypedData& metadata_payloads,
-    const ExternalTypedData& metadata_mappings,
-    const ExternalTypedData& constants_table,
     const Array& scripts,
     const Array& libraries_cache,
-    const Array& classes_cache,
-    const Object& retained_kernel_blob) {
-  const KernelProgramInfo& info =
-      KernelProgramInfo::Handle(KernelProgramInfo::New());
+    const Array& classes_cache) {
+  ASSERT(kernel_component.IsExternalOrExternalView());
+  ASSERT(string_data.IsExternalOrExternalView());
+  ASSERT(metadata_payloads.IsExternalOrExternalView());
+  ASSERT(metadata_mappings.IsExternalOrExternalView());
+  ASSERT(constants_table.IsExternalOrExternalView());
+
+  const auto& info = KernelProgramInfo::Handle(KernelProgramInfo::New());
+  info.untag()->set_kernel_component(kernel_component.ptr());
   info.untag()->set_string_offsets(string_offsets.ptr());
   info.untag()->set_string_data(string_data.ptr());
   info.untag()->set_canonical_names(canonical_names.ptr());
@@ -15201,7 +15200,6 @@
   info.untag()->set_constants_table(constants_table.ptr());
   info.untag()->set_libraries_cache(libraries_cache.ptr());
   info.untag()->set_classes_cache(classes_cache.ptr());
-  info.untag()->set_retained_kernel_blob(retained_kernel_blob.ptr());
   return info.ptr();
 }
 
@@ -15223,8 +15221,40 @@
   untag()->set_constants(constants.ptr());
 }
 
-void KernelProgramInfo::set_constants_table(
-    const ExternalTypedData& value) const {
+intptr_t KernelProgramInfo::KernelLibraryStartOffset(
+    intptr_t library_index) const {
+  const auto& blob = TypedDataBase::Handle(kernel_component());
+  const intptr_t library_count =
+      Utils::BigEndianToHost32(*reinterpret_cast<uint32_t*>(
+          blob.DataAddr(blob.LengthInBytes() - 2 * 4)));
+  const intptr_t library_start =
+      Utils::BigEndianToHost32(*reinterpret_cast<uint32_t*>(
+          blob.DataAddr(blob.LengthInBytes() -
+                        (2 + 1 + (library_count - library_index)) * 4)));
+  return library_start;
+}
+
+TypedDataViewPtr KernelProgramInfo::KernelLibrary(
+    intptr_t library_index) const {
+  const intptr_t start_offset = KernelLibraryStartOffset(library_index);
+  const intptr_t end_offset = KernelLibraryEndOffset(library_index);
+  const auto& component = TypedDataBase::Handle(kernel_component());
+  return component.ViewFromTo(start_offset, end_offset);
+}
+
+intptr_t KernelProgramInfo::KernelLibraryEndOffset(
+    intptr_t library_index) const {
+  const auto& blob = TypedDataBase::Handle(kernel_component());
+  const intptr_t library_count =
+      Utils::BigEndianToHost32(*reinterpret_cast<uint32_t*>(
+          blob.DataAddr(blob.LengthInBytes() - 2 * 4)));
+  const intptr_t library_end =
+      Utils::BigEndianToHost32(*reinterpret_cast<uint32_t*>(blob.DataAddr(
+          blob.LengthInBytes() - (2 + (library_count - library_index)) * 4)));
+  return library_end;
+}
+
+void KernelProgramInfo::set_constants_table(const TypedDataView& value) const {
   untag()->set_constants_table(value.ptr());
 }
 
@@ -26179,6 +26209,44 @@
   return result.ptr();
 }
 
+bool TypedDataBase::IsExternalOrExternalView() const {
+  if (IsExternalTypedData()) return true;
+  if (IsTypedDataView()) {
+    const auto& backing =
+        TypedDataBase::Handle(TypedDataView::Cast(*this).typed_data());
+    return backing.IsExternalTypedData();
+  }
+  return false;
+}
+
+TypedDataViewPtr TypedDataBase::ViewFromTo(intptr_t start,
+                                           intptr_t end,
+                                           Heap::Space space) const {
+  const intptr_t len = end - start;
+  ASSERT(0 <= len);
+  ASSERT(start < Length());
+  ASSERT((start + len) <= Length());
+
+  const intptr_t cid = GetClassId();
+
+  if (IsTypedDataView()) {
+    const auto& view = TypedDataView::Cast(*this);
+    const auto& td = TypedDataBase::Handle(view.typed_data());
+    const intptr_t view_offset = Smi::Value(view.offset_in_bytes());
+    ASSERT(IsTypedDataViewClassId(cid));
+    return TypedDataView::New(cid, ExternalTypedData::Cast(td),
+                              view_offset + start, len, Heap::kOld);
+  } else if (IsExternalTypedData()) {
+    ASSERT(IsExternalTypedDataClassId(cid));
+    ASSERT(IsTypedDataViewClassId(cid - 1));
+    return TypedDataView::New(cid - 1, *this, start, len, Heap::kOld);
+  }
+  RELEASE_ASSERT(IsTypedData());
+  ASSERT(IsExternalTypedDataClassId(cid));
+  ASSERT(IsTypedDataViewClassId(cid + 1));
+  return TypedDataView::New(cid + 1, *this, start, len, Heap::kOld);
+}
+
 const char* TypedDataBase::ToCString() const {
   // There are no instances of RawTypedDataBase.
   UNREACHABLE();
diff --git a/runtime/vm/object.h b/runtime/vm/object.h
index f49e0ac..5533da6 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -2239,21 +2239,16 @@
  public:
   ClassPtr wrapped_class() const { return untag()->wrapped_class(); }
   ScriptPtr script() const { return untag()->script(); }
-  ExternalTypedDataPtr library_kernel_data() const {
-    return untag()->library_kernel_data();
-  }
-  void set_library_kernel_data(const ExternalTypedData& data) const;
 
-  intptr_t library_kernel_offset() const {
+  intptr_t kernel_library_index() const {
 #if !defined(DART_PRECOMPILED_RUNTIME)
-    return untag()->library_kernel_offset_;
+    return untag()->kernel_library_index_;
 #else
     return -1;
 #endif
   }
-  void set_library_kernel_offset(intptr_t offset) const {
-    NOT_IN_PRECOMPILED(
-        StoreNonPointer(&untag()->library_kernel_offset_, offset));
+  void set_kernel_library_index(intptr_t index) const {
+    NOT_IN_PRECOMPILED(StoreNonPointer(&untag()->kernel_library_index_, index));
   }
 
 #if !defined(DART_PRECOMPILED_RUNTIME)
@@ -3555,15 +3550,15 @@
     set_optimized_call_site_count(value);
   }
 
-  void SetKernelDataAndEvalScript(
+  void SetKernelLibraryAndEvalScript(
       const Script& script,
       const class KernelProgramInfo& kernel_program_info,
-      const ExternalTypedData& data,
-      intptr_t offset) const;
+      intptr_t index) const;
 
-  intptr_t KernelDataProgramOffset() const;
+  intptr_t KernelLibraryOffset() const;
+  intptr_t KernelLibraryIndex() const;
 
-  ExternalTypedDataPtr KernelData() const;
+  TypedDataViewPtr KernelLibrary() const;
 
   bool IsOptimizable() const;
   void SetIsOptimizable(bool value) const;
@@ -4229,8 +4224,7 @@
   enum class EvalFunctionData {
     kScript,
     kKernelProgramInfo,
-    kKernelData,
-    kKernelOffset,
+    kKernelLibraryIndex,
     kLength,
   };
   enum NativeFunctionData {
@@ -4472,9 +4466,9 @@
 
   void InheritKernelOffsetFrom(const Field& src) const;
 
-  ExternalTypedDataPtr KernelData() const;
-
-  intptr_t KernelDataProgramOffset() const;
+  TypedDataViewPtr KernelLibrary() const;
+  intptr_t KernelLibraryOffset() const;
+  intptr_t KernelLibraryIndex() const;
 
   // Called during class finalization.
   inline void SetOffset(intptr_t host_offset_in_bytes,
@@ -4908,7 +4902,7 @@
   void InitializeFromKernel(const KernelProgramInfo& info,
                             intptr_t script_index,
                             const TypedData& line_starts,
-                            const ExternalTypedData& constant_coverage) const;
+                            const TypedDataView& constant_coverage) const;
 #endif
 
   // The index of this script into the [KernelProgramInfo] object's source
@@ -4922,7 +4916,7 @@
   TypedDataPtr line_starts() const;
 
 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
-  ExternalTypedDataPtr constant_coverage() const;
+  TypedDataViewPtr constant_coverage() const;
 #endif  // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
 
   LibraryPtr FindLibrary() const;
@@ -5286,25 +5280,24 @@
     return untag()->kernel_program_info();
   }
   void set_kernel_program_info(const KernelProgramInfo& info) const;
+  TypedDataViewPtr KernelLibrary() const;
+  intptr_t KernelLibraryOffset() const;
 #endif
 
-  ExternalTypedDataPtr kernel_data() const { return untag()->kernel_data(); }
-  void set_kernel_data(const ExternalTypedData& data) const;
-
-  intptr_t kernel_offset() const {
+  intptr_t kernel_library_index() const {
 #if defined(DART_PRECOMPILED_RUNTIME)
     return 0;
 #else
-    return untag()->kernel_offset_;
+    return untag()->kernel_library_index_;
 #endif
   }
 
-  void set_kernel_offset(intptr_t value) const {
+  void set_kernel_library_index(intptr_t value) const {
 #if defined(DART_PRECOMPILED_RUNTIME)
     UNREACHABLE();
 #else
     ASSERT(value >= 0);
-    StoreNonPointer(&untag()->kernel_offset_, value);
+    StoreNonPointer(&untag()->kernel_library_index_, value);
 #endif
   }
 
@@ -5473,16 +5466,16 @@
 
 class KernelProgramInfo : public Object {
  public:
-  static KernelProgramInfoPtr New(const TypedData& string_offsets,
-                                  const ExternalTypedData& string_data,
+  static KernelProgramInfoPtr New(const TypedDataBase& kernel_component,
+                                  const TypedDataView& string_data,
+                                  const TypedDataView& metadata_payload,
+                                  const TypedDataView& metadata_mappings,
+                                  const TypedDataView& constants_table,
+                                  const TypedData& string_offsets,
                                   const TypedData& canonical_names,
-                                  const ExternalTypedData& metadata_payload,
-                                  const ExternalTypedData& metadata_mappings,
-                                  const ExternalTypedData& constants_table,
                                   const Array& scripts,
                                   const Array& libraries_cache,
-                                  const Array& classes_cache,
-                                  const Object& retained_kernel_blob);
+                                  const Array& classes_cache);
 
   static intptr_t InstanceSize() {
     return RoundedAllocationSize(sizeof(UntaggedKernelProgramInfo));
@@ -5490,23 +5483,30 @@
 
   TypedDataPtr string_offsets() const { return untag()->string_offsets(); }
 
-  ExternalTypedDataPtr string_data() const { return untag()->string_data(); }
+  TypedDataBasePtr kernel_component() const {
+    return untag()->kernel_component();
+  }
+  TypedDataViewPtr string_data() const { return untag()->string_data(); }
 
   TypedDataPtr canonical_names() const { return untag()->canonical_names(); }
 
-  ExternalTypedDataPtr metadata_payloads() const {
+  TypedDataViewPtr metadata_payloads() const {
     return untag()->metadata_payloads();
   }
 
-  ExternalTypedDataPtr metadata_mappings() const {
+  TypedDataViewPtr metadata_mappings() const {
     return untag()->metadata_mappings();
   }
 
-  ExternalTypedDataPtr constants_table() const {
+  intptr_t KernelLibraryStartOffset(intptr_t library_index) const;
+  intptr_t KernelLibraryEndOffset(intptr_t library_index) const;
+  TypedDataViewPtr KernelLibrary(intptr_t library_index) const;
+
+  TypedDataViewPtr constants_table() const {
     return untag()->constants_table();
   }
 
-  void set_constants_table(const ExternalTypedData& value) const;
+  void set_constants_table(const TypedDataView& value) const;
 
   ArrayPtr scripts() const { return untag()->scripts(); }
   void set_scripts(const Array& scripts) const;
@@ -11659,6 +11659,11 @@
     }
   }
 
+  bool IsExternalOrExternalView() const;
+  TypedDataViewPtr ViewFromTo(intptr_t start,
+                              intptr_t end,
+                              Heap::Space space = Heap::kNew) const;
+
   void* DataAddr(intptr_t byte_offset) const {
     ASSERT((byte_offset == 0) ||
            ((byte_offset > 0) && (byte_offset < LengthInBytes())));
@@ -11907,7 +11912,7 @@
     return OFFSET_OF(UntaggedTypedDataView, offset_in_bytes_);
   }
 
-  InstancePtr typed_data() const { return untag()->typed_data(); }
+  TypedDataBasePtr typed_data() const { return untag()->typed_data(); }
 
   void InitializeWith(const TypedDataBase& typed_data,
                       intptr_t offset_in_bytes,
diff --git a/runtime/vm/object_reload.cc b/runtime/vm/object_reload.cc
index 0b82d2b..60af532 100644
--- a/runtime/vm/object_reload.cc
+++ b/runtime/vm/object_reload.cc
@@ -280,8 +280,7 @@
       PatchClass::New(*this, kernel_info, Script::Handle(script())));
   ASSERT(!patch.IsNull());
   const Library& lib = Library::Handle(library());
-  patch.set_library_kernel_data(ExternalTypedData::Handle(lib.kernel_data()));
-  patch.set_library_kernel_offset(lib.kernel_offset());
+  patch.set_kernel_library_index(lib.kernel_library_index());
 
   const Array& funcs = Array::Handle(current_functions());
   Function& func = Function::Handle();
diff --git a/runtime/vm/raw_object.h b/runtime/vm/raw_object.h
index 3083105..16b3076 100644
--- a/runtime/vm/raw_object.h
+++ b/runtime/vm/raw_object.h
@@ -1167,10 +1167,10 @@
   COMPRESSED_POINTER_FIELD(ScriptPtr, script)
 #if !defined(DART_PRECOMPILED_RUNTIME)
   COMPRESSED_POINTER_FIELD(KernelProgramInfoPtr, kernel_program_info)
+  VISIT_TO(kernel_program_info)
+#else
+  VISIT_TO(script)
 #endif
-  // A sub-view into the bytes of a kernel blob that encode the library.
-  COMPRESSED_POINTER_FIELD(ExternalTypedDataPtr, library_kernel_data)
-  VISIT_TO(library_kernel_data)
 
   CompressedObjectPtr* to_snapshot(Snapshot::Kind kind) {
     switch (kind) {
@@ -1179,7 +1179,12 @@
       case Snapshot::kFull:
       case Snapshot::kFullCore:
       case Snapshot::kFullJIT:
-        return reinterpret_cast<CompressedObjectPtr*>(&library_kernel_data_);
+#if !defined(DART_PRECOMPILED_RUNTIME)
+        return reinterpret_cast<CompressedObjectPtr*>(&kernel_program_info_);
+#else
+        UNREACHABLE();
+        return nullptr;
+#endif
       case Snapshot::kNone:
       case Snapshot::kInvalid:
         break;
@@ -1188,7 +1193,7 @@
     return nullptr;
   }
 
-  NOT_IN_PRECOMPILED(intptr_t library_kernel_offset_);
+  NOT_IN_PRECOMPILED(intptr_t kernel_library_index_);
 
   friend class Function;
 };
@@ -1587,7 +1592,7 @@
   COMPRESSED_POINTER_FIELD(StringPtr, resolved_url)
   COMPRESSED_POINTER_FIELD(TypedDataPtr, line_starts)
 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
-  COMPRESSED_POINTER_FIELD(ExternalTypedDataPtr, constant_coverage)
+  COMPRESSED_POINTER_FIELD(TypedDataViewPtr, constant_coverage)
 #endif  // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
   COMPRESSED_POINTER_FIELD(ArrayPtr, debug_positions)
   COMPRESSED_POINTER_FIELD(KernelProgramInfoPtr, kernel_program_info)
@@ -1690,8 +1695,6 @@
 #if !defined(DART_PRECOMPILED_RUNTIME)
   COMPRESSED_POINTER_FIELD(KernelProgramInfoPtr, kernel_program_info)
 #endif
-  // A sub-view into the bytes of a kernel blob that encode the library.
-  COMPRESSED_POINTER_FIELD(ExternalTypedDataPtr, kernel_data)
   CompressedObjectPtr* to_snapshot(Snapshot::Kind kind) {
     switch (kind) {
       case Snapshot::kFullAOT:
@@ -1699,7 +1702,12 @@
       case Snapshot::kFull:
       case Snapshot::kFullCore:
       case Snapshot::kFullJIT:
-        return reinterpret_cast<CompressedObjectPtr*>(&kernel_data_);
+#if !defined(DART_PRECOMPILED_RUNTIME)
+        return reinterpret_cast<CompressedObjectPtr*>(&kernel_program_info_);
+#else
+        UNREACHABLE();
+        return nullptr;
+#endif
       case Snapshot::kNone:
       case Snapshot::kInvalid:
         break;
@@ -1725,7 +1733,7 @@
   uint8_t flags_;         // BitField for LibraryFlags.
 
 #if !defined(DART_PRECOMPILED_RUNTIME)
-  uint32_t kernel_offset_;
+  uint32_t kernel_library_index_;
 #endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
   friend class Class;
@@ -1767,19 +1775,19 @@
 class UntaggedKernelProgramInfo : public UntaggedObject {
   RAW_HEAP_OBJECT_IMPLEMENTATION(KernelProgramInfo);
 
+  COMPRESSED_POINTER_FIELD(TypedDataBasePtr, kernel_component)
+  VISIT_FROM(kernel_component)
   COMPRESSED_POINTER_FIELD(TypedDataPtr, string_offsets)
-  VISIT_FROM(string_offsets)
-  COMPRESSED_POINTER_FIELD(ExternalTypedDataPtr, string_data)
+  COMPRESSED_POINTER_FIELD(TypedDataViewPtr, string_data)
   COMPRESSED_POINTER_FIELD(TypedDataPtr, canonical_names)
-  COMPRESSED_POINTER_FIELD(ExternalTypedDataPtr, metadata_payloads)
-  COMPRESSED_POINTER_FIELD(ExternalTypedDataPtr, metadata_mappings)
+  COMPRESSED_POINTER_FIELD(TypedDataViewPtr, metadata_payloads)
+  COMPRESSED_POINTER_FIELD(TypedDataViewPtr, metadata_mappings)
   COMPRESSED_POINTER_FIELD(ArrayPtr, scripts)
   COMPRESSED_POINTER_FIELD(ArrayPtr, constants)
-  COMPRESSED_POINTER_FIELD(ExternalTypedDataPtr, constants_table)
+  COMPRESSED_POINTER_FIELD(TypedDataViewPtr, constants_table)
   COMPRESSED_POINTER_FIELD(ArrayPtr, libraries_cache)
   COMPRESSED_POINTER_FIELD(ArrayPtr, classes_cache)
-  COMPRESSED_POINTER_FIELD(ObjectPtr, retained_kernel_blob)
-  VISIT_TO(retained_kernel_blob)
+  VISIT_TO(classes_cache)
 
   CompressedObjectPtr* to_snapshot(Snapshot::Kind kind) {
     return reinterpret_cast<CompressedObjectPtr*>(&constants_table_);
diff --git a/runtime/vm/raw_object_fields.cc b/runtime/vm/raw_object_fields.cc
index d19fcd6..4447623 100644
--- a/runtime/vm/raw_object_fields.cc
+++ b/runtime/vm/raw_object_fields.cc
@@ -30,7 +30,6 @@
   F(Class, invocation_dispatcher_cache_)                                       \
   F(PatchClass, wrapped_class_)                                                \
   F(PatchClass, script_)                                                       \
-  F(PatchClass, library_kernel_data_)                                          \
   F(Function, name_)                                                           \
   F(Function, owner_)                                                          \
   F(Function, signature_)                                                      \
@@ -64,7 +63,6 @@
   F(Library, imports_)                                                         \
   F(Library, exports_)                                                         \
   F(Library, dependencies_)                                                    \
-  F(Library, kernel_data_)                                                     \
   F(Library, resolved_names_)                                                  \
   F(Library, exported_names_)                                                  \
   F(Library, loaded_scripts_)                                                  \
@@ -72,6 +70,7 @@
   F(Namespace, show_names_)                                                    \
   F(Namespace, hide_names_)                                                    \
   F(Namespace, owner_)                                                         \
+  F(KernelProgramInfo, kernel_component_)                                      \
   F(KernelProgramInfo, string_offsets_)                                        \
   F(KernelProgramInfo, string_data_)                                           \
   F(KernelProgramInfo, canonical_names_)                                       \
@@ -82,7 +81,6 @@
   F(KernelProgramInfo, constants_table_)                                       \
   F(KernelProgramInfo, libraries_cache_)                                       \
   F(KernelProgramInfo, classes_cache_)                                         \
-  F(KernelProgramInfo, retained_kernel_blob_)                                  \
   F(WeakSerializationReference, target_)                                       \
   F(WeakSerializationReference, replacement_)                                  \
   F(WeakArray, length_)                                                        \