[vm] Reduce size of Class objects in AOT and PRODUCT modes

This change conditionally removes certain fields from Class objects
in AOT and PRODUCT modes.

Flutter gallery in release-sizeopt mode:
Snapshot size -0.47% (arm64), -0.44% (arm)
Heap size of snapshot objects -4.1% (arm64), -4.3% (arm)

On a large Flutter application compiled in --dwarf-stack-traces mode:
Heap size of Class objects -26%
Heap size of all snapshot objects -3.6%

TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/44020
Change-Id: I795c625b71558cd2f336f92fc326c36fd339cd4b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195700
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
diff --git a/runtime/vm/class_finalizer.cc b/runtime/vm/class_finalizer.cc
index 9d182ed..e429842 100644
--- a/runtime/vm/class_finalizer.cc
+++ b/runtime/vm/class_finalizer.cc
@@ -36,6 +36,15 @@
   return classes.Length() == 0;
 }
 
+#if defined(DART_PRECOMPILED_RUNTIME)
+
+bool ClassFinalizer::ProcessPendingClasses() {
+  ASSERT(AllClassesFinalized());
+  return true;
+}
+
+#else
+
 // Removes optimized code once we load more classes, since CHA based
 // optimizations may have become invalid.
 // Only methods which owner classes where subclasses can be invalid.
@@ -220,7 +229,6 @@
   return true;
 }
 
-#if !defined(DART_PRECOMPILED_RUNTIME)
 void ClassFinalizer::VerifyBootstrapClasses() {
   if (FLAG_trace_class_finalization) {
     OS::PrintErr("VerifyBootstrapClasses START.\n");
@@ -286,7 +294,6 @@
   }
   IsolateGroup::Current()->heap()->Verify();
 }
-#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
 void ClassFinalizer::FinalizeTypeParameters(const Class& cls,
                                             FinalizationKind finalization) {
@@ -310,6 +317,8 @@
   }
 }
 
+#endif  // defined(DART_PRECOMPILED_RUNTIME)
+
 // This function reports a compilation error if the recursive 'type' T being
 // finalized is a non-contractive type, i.e. if the induced type set S of P is
 // not finite, where P is the instantiation of T with its own type parameters.
@@ -533,7 +542,11 @@
                                            TrailPtr trail) {
   ASSERT(arguments.Length() >= cls.NumTypeArguments());
   if (!cls.is_type_finalized()) {
+#if defined(DART_PRECOMPILED_RUNTIME)
+    UNREACHABLE();
+#else
     FinalizeTypeParameters(cls, kFinalize);
+#endif  // defined(DART_PRECOMPILED_RUNTIME)
   }
   AbstractType& super_type = AbstractType::Handle(cls.super_type());
   if (!super_type.IsNull()) {
@@ -851,6 +864,8 @@
   return signature.ptr();
 }
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
+
 #if defined(TARGET_ARCH_X64)
 static bool IsPotentialExactGeneric(const AbstractType& type) {
   // TODO(dartbug.com/34170) Investigate supporting this for fields with types
@@ -956,6 +971,7 @@
     cls = type.type_class();
   }
 }
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
 void ClassFinalizer::FinalizeTypesInClass(const Class& cls) {
   Thread* thread = Thread::Current();
@@ -965,6 +981,9 @@
     return;
   }
 
+#if defined(DART_PRECOMPILED_RUNTIME)
+  UNREACHABLE();
+#else
   SafepointWriteRwLocker ml(thread, thread->isolate_group()->program_lock());
   if (cls.is_type_finalized()) {
     return;
@@ -1000,8 +1019,10 @@
   cls.set_is_type_finalized();
 
   RegisterClassInHierarchy(thread->zone(), cls);
+#endif  // defined(DART_PRECOMPILED_RUNTIME)
 }
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
 void ClassFinalizer::RegisterClassInHierarchy(Zone* zone, const Class& cls) {
   auto& type = AbstractType::Handle(zone, cls.super_type());
   auto& other_cls = Class::Handle(zone);
@@ -1025,6 +1046,7 @@
     other_cls.AddDirectImplementor(cls, /* is_mixin = */ i == mixin_index);
   }
 }
+#endif  // defined(DART_PRECOMPILED_RUNTIME)
 
 void ClassFinalizer::FinalizeClass(const Class& cls) {
   ASSERT(cls.is_type_finalized());
@@ -1032,6 +1054,9 @@
     return;
   }
 
+#if defined(DART_PRECOMPILED_RUNTIME)
+  UNREACHABLE();
+#else
   Thread* thread = Thread::Current();
   HANDLESCOPE(thread);
 
@@ -1048,7 +1073,6 @@
   }
 #endif  // defined(SUPPORT_TIMELINE)
 
-#if !defined(DART_PRECOMPILED_RUNTIME)
   // If loading from a kernel, make sure that the class is fully loaded.
   ASSERT(cls.IsTopLevel() || (cls.kernel_offset() > 0));
   if (!cls.is_loaded()) {
@@ -1057,7 +1081,6 @@
       return;
     }
   }
-#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
   // Ensure super class is finalized.
   const Class& super = Class::Handle(cls.SuperClass());
@@ -1084,8 +1107,11 @@
   if (cls.IsTopLevel()) {
     cls.set_is_allocate_finalized();
   }
+#endif  // defined(DART_PRECOMPILED_RUNTIME)
 }
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
+
 ErrorPtr ClassFinalizer::AllocateFinalizeClass(const Class& cls) {
   ASSERT(IsolateGroup::Current()->program_lock()->IsCurrentThreadWriter());
   ASSERT(cls.is_finalized());
@@ -1261,6 +1287,8 @@
   }
 }
 
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
+
 void ClassFinalizer::ReportError(const Error& error) {
   Report::LongJump(error);
   UNREACHABLE();
@@ -1276,6 +1304,8 @@
   UNREACHABLE();
 }
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
+
 void ClassFinalizer::VerifyImplicitFieldOffsets() {
 #ifdef DEBUG
   Thread* thread = Thread::Current();
@@ -1661,9 +1691,6 @@
 }
 
 void ClassFinalizer::ClearAllCode(bool including_nonchanging_cids) {
-#ifdef DART_PRECOMPILED_RUNTIME
-  UNREACHABLE();
-#else
   auto const thread = Thread::Current();
   auto const isolate_group = thread->isolate_group();
   SafepointWriteRwLocker ml(thread, isolate_group->program_lock());
@@ -1705,7 +1732,8 @@
     auto& null_code = Code::Handle(zone);
     object_store->set_build_method_extractor_code(null_code);
   }
-#endif  // !DART_PRECOMPILED_RUNTIME
 }
 
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
+
 }  // namespace dart
diff --git a/runtime/vm/class_finalizer.h b/runtime/vm/class_finalizer.h
index 623bdb5..db2b973 100644
--- a/runtime/vm/class_finalizer.h
+++ b/runtime/vm/class_finalizer.h
@@ -34,11 +34,13 @@
   // Return false if we still have classes pending to be finalized.
   static bool AllClassesFinalized();
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
   // Useful for sorting classes to make dispatch faster.
   static void SortClasses();
   static void RemapClassIds(intptr_t* old_to_new_cid);
   static void RehashTypes();
   static void ClearAllCode(bool including_nonchanging_cids = false);
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
   // Return whether processing pending classes (ObjectStore::pending_classes_)
   // failed. The function returns true if the processing was successful.
@@ -52,12 +54,16 @@
   // is an anonymous top level class).
   static void FinalizeTypesInClass(const Class& cls);
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
   // Register class in the lists of direct subclasses and direct implementors.
   static void RegisterClassInHierarchy(Zone* zone, const Class& cls);
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
   // Ensures members of the class are loaded, class layout is finalized and size
   // registered in class table.
   static void FinalizeClass(const Class& cls);
+
+#if !defined(DART_PRECOMPILED_RUNTIME)
   // Makes class instantiatable and usable by generated code.
   static ErrorPtr AllocateFinalizeClass(const Class& cls);
 
@@ -67,7 +73,6 @@
   // Returns Error::null() if there is no loading error.
   static ErrorPtr LoadClassMembers(const Class& cls);
 
-#if !defined(DART_PRECOMPILED_RUNTIME)
   // Verify that the classes have been properly prefinalized. This is
   // needed during bootstrapping where the classes have been preloaded.
   static void VerifyBootstrapClasses();
@@ -81,10 +86,13 @@
       FinalizationKind finalization = kCanonicalize,
       PendingTypes* pending_types = NULL);
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
   static void AllocateEnumValues(const Class& enum_cls);
   static void FinalizeTypeParameters(
       const Class& cls,
       FinalizationKind finalization = kCanonicalize);
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
+
   static intptr_t ExpandAndFinalizeTypeArguments(const AbstractType& type,
                                                  PendingTypes* pending_types);
   static void FinalizeTypeArguments(const Class& cls,
@@ -94,15 +102,20 @@
                                     TrailPtr trail);
   static void CheckRecursiveType(const AbstractType& type,
                                  PendingTypes* pending_types);
+
+#if !defined(DART_PRECOMPILED_RUNTIME)
   static void FinalizeMemberTypes(const Class& cls);
   static void PrintClassInformation(const Class& cls);
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
   static void ReportError(const Error& error);
   static void ReportError(const char* format, ...) PRINTF_ATTRIBUTE(1, 2);
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
   // Verify implicit offsets recorded in the VM for direct access to fields of
   // Dart instances (e.g: _TypedListView, _ByteDataView).
   static void VerifyImplicitFieldOffsets();
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 };
 
 }  // namespace dart
diff --git a/runtime/vm/clustered_snapshot.cc b/runtime/vm/clustered_snapshot.cc
index 8841d37b..89f9681 100644
--- a/runtime/vm/clustered_snapshot.cc
+++ b/runtime/vm/clustered_snapshot.cc
@@ -301,8 +301,10 @@
     s->Write<int32_t>(Class::target_type_arguments_field_offset_in_words(cls));
     s->Write<int16_t>(cls->untag()->num_type_arguments_);
     s->Write<uint16_t>(cls->untag()->num_native_fields_);
-    s->WriteTokenPosition(cls->untag()->token_pos_);
-    s->WriteTokenPosition(cls->untag()->end_token_pos_);
+    if (s->kind() != Snapshot::kFullAOT) {
+      s->WriteTokenPosition(cls->untag()->token_pos_);
+      s->WriteTokenPosition(cls->untag()->end_token_pos_);
+    }
     s->Write<uint32_t>(cls->untag()->state_bits_);
 
     // In AOT, the bitmap of unboxed fields should also be serialized
@@ -395,8 +397,11 @@
 #endif  //  !defined(DART_PRECOMPILED_RUNTIME)
       cls->untag()->num_type_arguments_ = d->Read<int16_t>();
       cls->untag()->num_native_fields_ = d->Read<uint16_t>();
+#if !defined(DART_PRECOMPILED_RUNTIME)
+      ASSERT(d->kind() != Snapshot::kFullAOT);
       cls->untag()->token_pos_ = d->ReadTokenPosition();
       cls->untag()->end_token_pos_ = d->ReadTokenPosition();
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
       cls->untag()->state_bits_ = d->Read<uint32_t>();
 
       if (FLAG_precompiled_mode) {
@@ -433,8 +438,11 @@
 #endif  //  !defined(DART_PRECOMPILED_RUNTIME)
       cls->untag()->num_type_arguments_ = d->Read<int16_t>();
       cls->untag()->num_native_fields_ = d->Read<uint16_t>();
+#if !defined(DART_PRECOMPILED_RUNTIME)
+      ASSERT(d->kind() != Snapshot::kFullAOT);
       cls->untag()->token_pos_ = d->ReadTokenPosition();
       cls->untag()->end_token_pos_ = d->ReadTokenPosition();
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
       cls->untag()->state_bits_ = d->Read<uint32_t>();
 
       table->AllocateIndex(class_id);
diff --git a/runtime/vm/compilation_trace.h b/runtime/vm/compilation_trace.h
index aa4a6b7..14996ec 100644
--- a/runtime/vm/compilation_trace.h
+++ b/runtime/vm/compilation_trace.h
@@ -10,6 +10,8 @@
 #include "vm/program_visitor.h"
 #include "vm/zone_text_buffer.h"
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
+
 namespace dart {
 
 class CompilationTraceSaver : public FunctionVisitor {
@@ -134,4 +136,6 @@
 
 }  // namespace dart
 
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
+
 #endif  // RUNTIME_VM_COMPILATION_TRACE_H_
diff --git a/runtime/vm/compiler/runtime_offsets_extracted.h b/runtime/vm/compiler/runtime_offsets_extracted.h
index 5af8a8b..1337ee3 100644
--- a/runtime/vm/compiler/runtime_offsets_extracted.h
+++ b/runtime/vm/compiler/runtime_offsets_extracted.h
@@ -3330,12 +3330,12 @@
 static constexpr dart::compiler::target::word Array_tags_offset = 0;
 static constexpr dart::compiler::target::word Array_type_arguments_offset = 4;
 static constexpr dart::compiler::target::word Class_declaration_type_offset =
-    52;
+    48;
 static constexpr dart::compiler::target::word Class_num_type_arguments_offset =
-    88;
-static constexpr dart::compiler::target::word Class_super_type_offset = 44;
+    84;
+static constexpr dart::compiler::target::word Class_super_type_offset = 40;
 static constexpr dart::compiler::target::word
-    Class_host_type_arguments_field_offset_in_words_offset = 100;
+    Class_host_type_arguments_field_offset_in_words_offset = 96;
 static constexpr dart::compiler::target::word Closure_context_offset = 20;
 static constexpr dart::compiler::target::word
     Closure_delayed_type_arguments_offset = 12;
@@ -3688,7 +3688,7 @@
 static constexpr dart::compiler::target::word Array_header_size = 12;
 static constexpr dart::compiler::target::word Bool_InstanceSize = 8;
 static constexpr dart::compiler::target::word Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word Class_InstanceSize = 124;
+static constexpr dart::compiler::target::word Class_InstanceSize = 120;
 static constexpr dart::compiler::target::word Closure_InstanceSize = 28;
 static constexpr dart::compiler::target::word ClosureData_InstanceSize = 24;
 static constexpr dart::compiler::target::word Code_InstanceSize = 76;
@@ -3860,12 +3860,12 @@
 static constexpr dart::compiler::target::word Array_tags_offset = 0;
 static constexpr dart::compiler::target::word Array_type_arguments_offset = 8;
 static constexpr dart::compiler::target::word Class_declaration_type_offset =
-    104;
+    96;
 static constexpr dart::compiler::target::word Class_num_type_arguments_offset =
-    164;
-static constexpr dart::compiler::target::word Class_super_type_offset = 88;
+    156;
+static constexpr dart::compiler::target::word Class_super_type_offset = 80;
 static constexpr dart::compiler::target::word
-    Class_host_type_arguments_field_offset_in_words_offset = 176;
+    Class_host_type_arguments_field_offset_in_words_offset = 168;
 static constexpr dart::compiler::target::word Closure_context_offset = 40;
 static constexpr dart::compiler::target::word
     Closure_delayed_type_arguments_offset = 24;
@@ -4224,7 +4224,7 @@
 static constexpr dart::compiler::target::word Array_header_size = 24;
 static constexpr dart::compiler::target::word Bool_InstanceSize = 16;
 static constexpr dart::compiler::target::word Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word Class_InstanceSize = 200;
+static constexpr dart::compiler::target::word Class_InstanceSize = 192;
 static constexpr dart::compiler::target::word Closure_InstanceSize = 56;
 static constexpr dart::compiler::target::word ClosureData_InstanceSize = 48;
 static constexpr dart::compiler::target::word Code_InstanceSize = 144;
@@ -4395,12 +4395,12 @@
 static constexpr dart::compiler::target::word Array_tags_offset = 0;
 static constexpr dart::compiler::target::word Array_type_arguments_offset = 4;
 static constexpr dart::compiler::target::word Class_declaration_type_offset =
-    52;
+    48;
 static constexpr dart::compiler::target::word Class_num_type_arguments_offset =
-    88;
-static constexpr dart::compiler::target::word Class_super_type_offset = 44;
+    84;
+static constexpr dart::compiler::target::word Class_super_type_offset = 40;
 static constexpr dart::compiler::target::word
-    Class_host_type_arguments_field_offset_in_words_offset = 100;
+    Class_host_type_arguments_field_offset_in_words_offset = 96;
 static constexpr dart::compiler::target::word Closure_context_offset = 20;
 static constexpr dart::compiler::target::word
     Closure_delayed_type_arguments_offset = 12;
@@ -4750,7 +4750,7 @@
 static constexpr dart::compiler::target::word Array_header_size = 12;
 static constexpr dart::compiler::target::word Bool_InstanceSize = 8;
 static constexpr dart::compiler::target::word Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word Class_InstanceSize = 124;
+static constexpr dart::compiler::target::word Class_InstanceSize = 120;
 static constexpr dart::compiler::target::word Closure_InstanceSize = 28;
 static constexpr dart::compiler::target::word ClosureData_InstanceSize = 24;
 static constexpr dart::compiler::target::word Code_InstanceSize = 76;
@@ -4922,12 +4922,12 @@
 static constexpr dart::compiler::target::word Array_tags_offset = 0;
 static constexpr dart::compiler::target::word Array_type_arguments_offset = 8;
 static constexpr dart::compiler::target::word Class_declaration_type_offset =
-    104;
+    96;
 static constexpr dart::compiler::target::word Class_num_type_arguments_offset =
-    164;
-static constexpr dart::compiler::target::word Class_super_type_offset = 88;
+    156;
+static constexpr dart::compiler::target::word Class_super_type_offset = 80;
 static constexpr dart::compiler::target::word
-    Class_host_type_arguments_field_offset_in_words_offset = 176;
+    Class_host_type_arguments_field_offset_in_words_offset = 168;
 static constexpr dart::compiler::target::word Closure_context_offset = 40;
 static constexpr dart::compiler::target::word
     Closure_delayed_type_arguments_offset = 24;
@@ -5287,7 +5287,7 @@
 static constexpr dart::compiler::target::word Array_header_size = 24;
 static constexpr dart::compiler::target::word Bool_InstanceSize = 16;
 static constexpr dart::compiler::target::word Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word Class_InstanceSize = 200;
+static constexpr dart::compiler::target::word Class_InstanceSize = 192;
 static constexpr dart::compiler::target::word Closure_InstanceSize = 56;
 static constexpr dart::compiler::target::word ClosureData_InstanceSize = 48;
 static constexpr dart::compiler::target::word Code_InstanceSize = 144;
@@ -5458,12 +5458,12 @@
 static constexpr dart::compiler::target::word Array_tags_offset = 0;
 static constexpr dart::compiler::target::word Array_type_arguments_offset = 8;
 static constexpr dart::compiler::target::word Class_declaration_type_offset =
-    56;
+    52;
 static constexpr dart::compiler::target::word Class_num_type_arguments_offset =
-    92;
-static constexpr dart::compiler::target::word Class_super_type_offset = 48;
+    88;
+static constexpr dart::compiler::target::word Class_super_type_offset = 44;
 static constexpr dart::compiler::target::word
-    Class_host_type_arguments_field_offset_in_words_offset = 104;
+    Class_host_type_arguments_field_offset_in_words_offset = 100;
 static constexpr dart::compiler::target::word Closure_context_offset = 40;
 static constexpr dart::compiler::target::word
     Closure_delayed_type_arguments_offset = 24;
@@ -5993,12 +5993,12 @@
 static constexpr dart::compiler::target::word Array_tags_offset = 0;
 static constexpr dart::compiler::target::word Array_type_arguments_offset = 8;
 static constexpr dart::compiler::target::word Class_declaration_type_offset =
-    56;
+    52;
 static constexpr dart::compiler::target::word Class_num_type_arguments_offset =
-    92;
-static constexpr dart::compiler::target::word Class_super_type_offset = 48;
+    88;
+static constexpr dart::compiler::target::word Class_super_type_offset = 44;
 static constexpr dart::compiler::target::word
-    Class_host_type_arguments_field_offset_in_words_offset = 104;
+    Class_host_type_arguments_field_offset_in_words_offset = 100;
 static constexpr dart::compiler::target::word Closure_context_offset = 40;
 static constexpr dart::compiler::target::word
     Closure_delayed_type_arguments_offset = 24;
@@ -6536,10 +6536,10 @@
 static constexpr dart::compiler::target::word
     AOT_Class_declaration_type_offset = 52;
 static constexpr dart::compiler::target::word
-    AOT_Class_num_type_arguments_offset = 88;
+    AOT_Class_num_type_arguments_offset = 72;
 static constexpr dart::compiler::target::word AOT_Class_super_type_offset = 44;
 static constexpr dart::compiler::target::word
-    AOT_Class_host_type_arguments_field_offset_in_words_offset = 100;
+    AOT_Class_host_type_arguments_field_offset_in_words_offset = 84;
 static constexpr dart::compiler::target::word
     AOT_SharedClassTable_class_heap_stats_table_offset = 0;
 static constexpr dart::compiler::target::word AOT_Closure_context_offset = 20;
@@ -6942,7 +6942,7 @@
 static constexpr dart::compiler::target::word AOT_Array_header_size = 12;
 static constexpr dart::compiler::target::word AOT_Bool_InstanceSize = 8;
 static constexpr dart::compiler::target::word AOT_Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 108;
+static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 92;
 static constexpr dart::compiler::target::word AOT_Closure_InstanceSize = 28;
 static constexpr dart::compiler::target::word AOT_ClosureData_InstanceSize = 24;
 static constexpr dart::compiler::target::word AOT_Code_InstanceSize = 88;
@@ -7133,10 +7133,10 @@
 static constexpr dart::compiler::target::word
     AOT_Class_declaration_type_offset = 104;
 static constexpr dart::compiler::target::word
-    AOT_Class_num_type_arguments_offset = 164;
+    AOT_Class_num_type_arguments_offset = 140;
 static constexpr dart::compiler::target::word AOT_Class_super_type_offset = 88;
 static constexpr dart::compiler::target::word
-    AOT_Class_host_type_arguments_field_offset_in_words_offset = 176;
+    AOT_Class_host_type_arguments_field_offset_in_words_offset = 152;
 static constexpr dart::compiler::target::word
     AOT_SharedClassTable_class_heap_stats_table_offset = 0;
 static constexpr dart::compiler::target::word AOT_Closure_context_offset = 40;
@@ -7542,7 +7542,7 @@
 static constexpr dart::compiler::target::word AOT_Array_header_size = 24;
 static constexpr dart::compiler::target::word AOT_Bool_InstanceSize = 16;
 static constexpr dart::compiler::target::word AOT_Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 184;
+static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 160;
 static constexpr dart::compiler::target::word AOT_Closure_InstanceSize = 56;
 static constexpr dart::compiler::target::word AOT_ClosureData_InstanceSize = 48;
 static constexpr dart::compiler::target::word AOT_Code_InstanceSize = 152;
@@ -7736,10 +7736,10 @@
 static constexpr dart::compiler::target::word
     AOT_Class_declaration_type_offset = 104;
 static constexpr dart::compiler::target::word
-    AOT_Class_num_type_arguments_offset = 164;
+    AOT_Class_num_type_arguments_offset = 140;
 static constexpr dart::compiler::target::word AOT_Class_super_type_offset = 88;
 static constexpr dart::compiler::target::word
-    AOT_Class_host_type_arguments_field_offset_in_words_offset = 176;
+    AOT_Class_host_type_arguments_field_offset_in_words_offset = 152;
 static constexpr dart::compiler::target::word
     AOT_SharedClassTable_class_heap_stats_table_offset = 0;
 static constexpr dart::compiler::target::word AOT_Closure_context_offset = 40;
@@ -8146,7 +8146,7 @@
 static constexpr dart::compiler::target::word AOT_Array_header_size = 24;
 static constexpr dart::compiler::target::word AOT_Bool_InstanceSize = 16;
 static constexpr dart::compiler::target::word AOT_Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 184;
+static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 160;
 static constexpr dart::compiler::target::word AOT_Closure_InstanceSize = 56;
 static constexpr dart::compiler::target::word AOT_ClosureData_InstanceSize = 48;
 static constexpr dart::compiler::target::word AOT_Code_InstanceSize = 152;
@@ -8337,10 +8337,10 @@
 static constexpr dart::compiler::target::word
     AOT_Class_declaration_type_offset = 56;
 static constexpr dart::compiler::target::word
-    AOT_Class_num_type_arguments_offset = 92;
+    AOT_Class_num_type_arguments_offset = 76;
 static constexpr dart::compiler::target::word AOT_Class_super_type_offset = 48;
 static constexpr dart::compiler::target::word
-    AOT_Class_host_type_arguments_field_offset_in_words_offset = 104;
+    AOT_Class_host_type_arguments_field_offset_in_words_offset = 88;
 static constexpr dart::compiler::target::word
     AOT_SharedClassTable_class_heap_stats_table_offset = 0;
 static constexpr dart::compiler::target::word AOT_Closure_context_offset = 40;
@@ -8746,7 +8746,7 @@
 static constexpr dart::compiler::target::word AOT_Array_header_size = 24;
 static constexpr dart::compiler::target::word AOT_Bool_InstanceSize = 16;
 static constexpr dart::compiler::target::word AOT_Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 112;
+static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 96;
 static constexpr dart::compiler::target::word AOT_Closure_InstanceSize = 56;
 static constexpr dart::compiler::target::word AOT_ClosureData_InstanceSize = 32;
 static constexpr dart::compiler::target::word AOT_Code_InstanceSize = 152;
@@ -8937,10 +8937,10 @@
 static constexpr dart::compiler::target::word
     AOT_Class_declaration_type_offset = 56;
 static constexpr dart::compiler::target::word
-    AOT_Class_num_type_arguments_offset = 92;
+    AOT_Class_num_type_arguments_offset = 76;
 static constexpr dart::compiler::target::word AOT_Class_super_type_offset = 48;
 static constexpr dart::compiler::target::word
-    AOT_Class_host_type_arguments_field_offset_in_words_offset = 104;
+    AOT_Class_host_type_arguments_field_offset_in_words_offset = 88;
 static constexpr dart::compiler::target::word
     AOT_SharedClassTable_class_heap_stats_table_offset = 0;
 static constexpr dart::compiler::target::word AOT_Closure_context_offset = 40;
@@ -9347,7 +9347,7 @@
 static constexpr dart::compiler::target::word AOT_Array_header_size = 24;
 static constexpr dart::compiler::target::word AOT_Bool_InstanceSize = 16;
 static constexpr dart::compiler::target::word AOT_Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 112;
+static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 96;
 static constexpr dart::compiler::target::word AOT_Closure_InstanceSize = 56;
 static constexpr dart::compiler::target::word AOT_ClosureData_InstanceSize = 32;
 static constexpr dart::compiler::target::word AOT_Code_InstanceSize = 152;
@@ -9537,12 +9537,12 @@
 static constexpr dart::compiler::target::word AOT_Array_type_arguments_offset =
     4;
 static constexpr dart::compiler::target::word
-    AOT_Class_declaration_type_offset = 52;
+    AOT_Class_declaration_type_offset = 48;
 static constexpr dart::compiler::target::word
-    AOT_Class_num_type_arguments_offset = 88;
-static constexpr dart::compiler::target::word AOT_Class_super_type_offset = 44;
+    AOT_Class_num_type_arguments_offset = 60;
+static constexpr dart::compiler::target::word AOT_Class_super_type_offset = 40;
 static constexpr dart::compiler::target::word
-    AOT_Class_host_type_arguments_field_offset_in_words_offset = 100;
+    AOT_Class_host_type_arguments_field_offset_in_words_offset = 72;
 static constexpr dart::compiler::target::word AOT_Closure_context_offset = 20;
 static constexpr dart::compiler::target::word
     AOT_Closure_delayed_type_arguments_offset = 12;
@@ -9938,7 +9938,7 @@
 static constexpr dart::compiler::target::word AOT_Array_header_size = 12;
 static constexpr dart::compiler::target::word AOT_Bool_InstanceSize = 8;
 static constexpr dart::compiler::target::word AOT_Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 108;
+static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 80;
 static constexpr dart::compiler::target::word AOT_Closure_InstanceSize = 28;
 static constexpr dart::compiler::target::word AOT_ClosureData_InstanceSize = 24;
 static constexpr dart::compiler::target::word AOT_Code_InstanceSize = 64;
@@ -10127,12 +10127,12 @@
 static constexpr dart::compiler::target::word AOT_Array_type_arguments_offset =
     8;
 static constexpr dart::compiler::target::word
-    AOT_Class_declaration_type_offset = 104;
+    AOT_Class_declaration_type_offset = 96;
 static constexpr dart::compiler::target::word
-    AOT_Class_num_type_arguments_offset = 164;
-static constexpr dart::compiler::target::word AOT_Class_super_type_offset = 88;
+    AOT_Class_num_type_arguments_offset = 116;
+static constexpr dart::compiler::target::word AOT_Class_super_type_offset = 80;
 static constexpr dart::compiler::target::word
-    AOT_Class_host_type_arguments_field_offset_in_words_offset = 176;
+    AOT_Class_host_type_arguments_field_offset_in_words_offset = 128;
 static constexpr dart::compiler::target::word AOT_Closure_context_offset = 40;
 static constexpr dart::compiler::target::word
     AOT_Closure_delayed_type_arguments_offset = 24;
@@ -10531,7 +10531,7 @@
 static constexpr dart::compiler::target::word AOT_Array_header_size = 24;
 static constexpr dart::compiler::target::word AOT_Bool_InstanceSize = 16;
 static constexpr dart::compiler::target::word AOT_Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 184;
+static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 136;
 static constexpr dart::compiler::target::word AOT_Closure_InstanceSize = 56;
 static constexpr dart::compiler::target::word AOT_ClosureData_InstanceSize = 48;
 static constexpr dart::compiler::target::word AOT_Code_InstanceSize = 120;
@@ -10723,12 +10723,12 @@
 static constexpr dart::compiler::target::word AOT_Array_type_arguments_offset =
     8;
 static constexpr dart::compiler::target::word
-    AOT_Class_declaration_type_offset = 104;
+    AOT_Class_declaration_type_offset = 96;
 static constexpr dart::compiler::target::word
-    AOT_Class_num_type_arguments_offset = 164;
-static constexpr dart::compiler::target::word AOT_Class_super_type_offset = 88;
+    AOT_Class_num_type_arguments_offset = 116;
+static constexpr dart::compiler::target::word AOT_Class_super_type_offset = 80;
 static constexpr dart::compiler::target::word
-    AOT_Class_host_type_arguments_field_offset_in_words_offset = 176;
+    AOT_Class_host_type_arguments_field_offset_in_words_offset = 128;
 static constexpr dart::compiler::target::word AOT_Closure_context_offset = 40;
 static constexpr dart::compiler::target::word
     AOT_Closure_delayed_type_arguments_offset = 24;
@@ -11128,7 +11128,7 @@
 static constexpr dart::compiler::target::word AOT_Array_header_size = 24;
 static constexpr dart::compiler::target::word AOT_Bool_InstanceSize = 16;
 static constexpr dart::compiler::target::word AOT_Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 184;
+static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 136;
 static constexpr dart::compiler::target::word AOT_Closure_InstanceSize = 56;
 static constexpr dart::compiler::target::word AOT_ClosureData_InstanceSize = 48;
 static constexpr dart::compiler::target::word AOT_Code_InstanceSize = 120;
@@ -11317,12 +11317,12 @@
 static constexpr dart::compiler::target::word AOT_Array_type_arguments_offset =
     8;
 static constexpr dart::compiler::target::word
-    AOT_Class_declaration_type_offset = 56;
+    AOT_Class_declaration_type_offset = 52;
 static constexpr dart::compiler::target::word
-    AOT_Class_num_type_arguments_offset = 92;
-static constexpr dart::compiler::target::word AOT_Class_super_type_offset = 48;
+    AOT_Class_num_type_arguments_offset = 64;
+static constexpr dart::compiler::target::word AOT_Class_super_type_offset = 44;
 static constexpr dart::compiler::target::word
-    AOT_Class_host_type_arguments_field_offset_in_words_offset = 104;
+    AOT_Class_host_type_arguments_field_offset_in_words_offset = 76;
 static constexpr dart::compiler::target::word AOT_Closure_context_offset = 40;
 static constexpr dart::compiler::target::word
     AOT_Closure_delayed_type_arguments_offset = 24;
@@ -11721,7 +11721,7 @@
 static constexpr dart::compiler::target::word AOT_Array_header_size = 24;
 static constexpr dart::compiler::target::word AOT_Bool_InstanceSize = 16;
 static constexpr dart::compiler::target::word AOT_Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 112;
+static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 88;
 static constexpr dart::compiler::target::word AOT_Closure_InstanceSize = 56;
 static constexpr dart::compiler::target::word AOT_ClosureData_InstanceSize = 32;
 static constexpr dart::compiler::target::word AOT_Code_InstanceSize = 120;
@@ -11910,12 +11910,12 @@
 static constexpr dart::compiler::target::word AOT_Array_type_arguments_offset =
     8;
 static constexpr dart::compiler::target::word
-    AOT_Class_declaration_type_offset = 56;
+    AOT_Class_declaration_type_offset = 52;
 static constexpr dart::compiler::target::word
-    AOT_Class_num_type_arguments_offset = 92;
-static constexpr dart::compiler::target::word AOT_Class_super_type_offset = 48;
+    AOT_Class_num_type_arguments_offset = 64;
+static constexpr dart::compiler::target::word AOT_Class_super_type_offset = 44;
 static constexpr dart::compiler::target::word
-    AOT_Class_host_type_arguments_field_offset_in_words_offset = 104;
+    AOT_Class_host_type_arguments_field_offset_in_words_offset = 76;
 static constexpr dart::compiler::target::word AOT_Closure_context_offset = 40;
 static constexpr dart::compiler::target::word
     AOT_Closure_delayed_type_arguments_offset = 24;
@@ -12315,7 +12315,7 @@
 static constexpr dart::compiler::target::word AOT_Array_header_size = 24;
 static constexpr dart::compiler::target::word AOT_Bool_InstanceSize = 16;
 static constexpr dart::compiler::target::word AOT_Capability_InstanceSize = 16;
-static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 112;
+static constexpr dart::compiler::target::word AOT_Class_InstanceSize = 88;
 static constexpr dart::compiler::target::word AOT_Closure_InstanceSize = 56;
 static constexpr dart::compiler::target::word AOT_ClosureData_InstanceSize = 32;
 static constexpr dart::compiler::target::word AOT_Code_InstanceSize = 120;
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 4256646..fb463cf 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -2829,8 +2829,8 @@
     result ^= raw;
   }
   Object::VerifyBuiltinVtable<FakeObject>(FakeObject::kClassId);
-  result.set_token_pos(TokenPosition::kNoSource);
-  result.set_end_token_pos(TokenPosition::kNoSource);
+  NOT_IN_PRECOMPILED(result.set_token_pos(TokenPosition::kNoSource));
+  NOT_IN_PRECOMPILED(result.set_end_token_pos(TokenPosition::kNoSource));
   result.set_instance_size(FakeObject::InstanceSize(),
                            compiler::target::RoundedAllocationSize(
                                TargetFakeObject::InstanceSize()));
@@ -2865,6 +2865,7 @@
   return result.ptr();
 }
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
 static void ReportTooManyTypeArguments(const Class& cls) {
   Report::MessageF(Report::kError, Script::Handle(cls.script()),
                    cls.token_pos(), Report::AtLocation,
@@ -2873,8 +2874,12 @@
                    String::Handle(cls.Name()).ToCString());
   UNREACHABLE();
 }
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
 void Class::set_num_type_arguments(intptr_t value) const {
+#if defined(DART_PRECOMPILED_RUNTIME)
+  UNREACHABLE();
+#else
   if (!Utils::IsInt(16, value)) {
     ReportTooManyTypeArguments(*this);
   }
@@ -2884,6 +2889,7 @@
   DEBUG_ASSERT(old_value == kUnknownNumTypeArguments || old_value == value);
   StoreNonPointer<int16_t, int16_t, std::memory_order_relaxed>(
       &untag()->num_type_arguments_, value);
+#endif  // defined(DART_PRECOMPILED_RUNTIME)
 }
 
 void Class::set_num_type_arguments_unsafe(intptr_t value) const {
@@ -3272,10 +3278,15 @@
     return num_type_args;
   }
 
+#if defined(DART_PRECOMPILED_RUNTIME)
+  UNREACHABLE();
+  return 0;
+#else
   num_type_args = ComputeNumTypeArguments();
   ASSERT(num_type_args != kUnknownNumTypeArguments);
   set_num_type_arguments(num_type_args);
   return num_type_args;
+#endif  // defined(DART_PRECOMPILED_RUNTIME)
 }
 
 static TypeArgumentsPtr InstantiateTypeArgumentsToBounds(
@@ -3943,6 +3954,15 @@
   set_is_finalized();
 }
 
+#if defined(DEBUG)
+static bool IsMutatorOrAtSafepoint() {
+  Thread* thread = Thread::Current();
+  return thread->IsMutatorThread() || thread->IsAtSafepoint();
+}
+#endif
+
+#if !defined(DART_PRECOMPILED_RUNTIME)
+
 class CHACodeArray : public WeakCodeReferences {
  public:
   explicit CHACodeArray(const Class& cls)
@@ -3976,13 +3996,6 @@
   DISALLOW_COPY_AND_ASSIGN(CHACodeArray);
 };
 
-#if defined(DEBUG)
-static bool IsMutatorOrAtSafepoint() {
-  Thread* thread = Thread::Current();
-  return thread->IsMutatorThread() || thread->IsAtSafepoint();
-}
-#endif
-
 void Class::RegisterCHACode(const Code& code) {
   if (FLAG_trace_cha) {
     THR_Print("RegisterCHACode '%s' depends on class '%s'\n",
@@ -4013,6 +4026,20 @@
   DisableCHAOptimizedCode(Class::Handle());
 }
 
+ArrayPtr Class::dependent_code() const {
+  DEBUG_ASSERT(
+      IsolateGroup::Current()->program_lock()->IsCurrentThreadReader());
+  return untag()->dependent_code();
+}
+
+void Class::set_dependent_code(const Array& array) const {
+  DEBUG_ASSERT(
+      IsolateGroup::Current()->program_lock()->IsCurrentThreadWriter());
+  untag()->set_dependent_code(array.ptr());
+}
+
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
+
 bool Class::TraceAllocation(IsolateGroup* isolate_group) const {
 #ifndef PRODUCT
   auto class_table = isolate_group->shared_class_table();
@@ -4036,18 +4063,6 @@
 #endif
 }
 
-ArrayPtr Class::dependent_code() const {
-  DEBUG_ASSERT(
-      IsolateGroup::Current()->program_lock()->IsCurrentThreadReader());
-  return untag()->dependent_code();
-}
-
-void Class::set_dependent_code(const Array& array) const {
-  DEBUG_ASSERT(
-      IsolateGroup::Current()->program_lock()->IsCurrentThreadWriter());
-  untag()->set_dependent_code(array.ptr());
-}
-
 // Conventions:
 // * For throwing a NSM in a class klass we use its runtime type as receiver,
 //   i.e., klass.RareType().
@@ -4377,6 +4392,10 @@
   if (is_finalized()) {
     return Error::null();
   }
+#if defined(DART_PRECOMPILED_RUNTIME)
+  UNREACHABLE();
+  return Error::null();
+#else
   SafepointWriteRwLocker ml(thread, thread->isolate_group()->program_lock());
   if (is_finalized()) {
     return Error::null();
@@ -4393,6 +4412,7 @@
     }
   }
   return error.ptr();
+#endif  // defined(DART_PRECOMPILED_RUNTIME)
 }
 
 // Ensure that code outdated by finalized class is cleaned up, new instance of
@@ -4419,7 +4439,11 @@
   if (is_allocate_finalized()) {
     return Error::null();
   }
+#if defined(DART_PRECOMPILED_RUNTIME)
+  UNREACHABLE();
+#else
   error ^= ClassFinalizer::AllocateFinalizeClass(*this);
+#endif  // defined(DART_PRECOMPILED_RUNTIME)
   return error.ptr();
 }
 
@@ -4535,8 +4559,8 @@
   // Here kIllegalCid means not-yet-assigned.
   Object::VerifyBuiltinVtable<FakeInstance>(index == kIllegalCid ? kInstanceCid
                                                                  : index);
-  result.set_token_pos(TokenPosition::kNoSource);
-  result.set_end_token_pos(TokenPosition::kNoSource);
+  NOT_IN_PRECOMPILED(result.set_token_pos(TokenPosition::kNoSource));
+  NOT_IN_PRECOMPILED(result.set_end_token_pos(TokenPosition::kNoSource));
   const intptr_t host_instance_size = FakeInstance::InstanceSize();
   const intptr_t target_instance_size = compiler::target::RoundedAllocationSize(
       TargetFakeInstance::InstanceSize());
@@ -4583,7 +4607,7 @@
   result.set_library(lib);
   result.set_name(name);
   result.set_script(script);
-  result.set_token_pos(token_pos);
+  NOT_IN_PRECOMPILED(result.set_token_pos(token_pos));
 
   // The size gets initialized to 0. Once the class gets finalized the class
   // finalizer will set the correct size.
@@ -4941,6 +4965,7 @@
   untag()->set_script(value.ptr());
 }
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
 void Class::set_token_pos(TokenPosition token_pos) const {
   ASSERT(!token_pos.IsClassifying());
   StoreNonPointer(&untag()->token_pos_, token_pos);
@@ -4950,6 +4975,7 @@
   ASSERT(!token_pos.IsClassifying());
   StoreNonPointer(&untag()->end_token_pos_, token_pos);
 }
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
 int32_t Class::SourceFingerprint() const {
 #if !defined(DART_PRECOMPILED_RUNTIME)
@@ -5062,6 +5088,8 @@
   untag()->set_interfaces(value.ptr());
 }
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
+
 void Class::AddDirectImplementor(const Class& implementor,
                                  bool is_mixin) const {
   ASSERT(IsolateGroup::Current()->program_lock()->IsCurrentThreadWriter());
@@ -5120,6 +5148,8 @@
   untag()->set_direct_subclasses(subclasses.ptr());
 }
 
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
+
 ArrayPtr Class::constants() const {
   return untag()->constants();
 }
@@ -5167,6 +5197,7 @@
   return type.ptr();
 }
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
 void Class::set_allocation_stub(const Code& value) const {
   // Never clear the stub as it may still be a target, but will be GC-d if
   // not referenced.
@@ -5174,8 +5205,12 @@
   ASSERT(untag()->allocation_stub() == Code::null());
   untag()->set_allocation_stub(value.ptr());
 }
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
 void Class::DisableAllocationStub() const {
+#if defined(DART_PRECOMPILED_RUNTIME)
+  UNREACHABLE();
+#else
   {
     const Code& existing_stub = Code::Handle(allocation_stub());
     if (existing_stub.IsNull()) {
@@ -5193,6 +5228,7 @@
   existing_stub.DisableStubCode();
   // Disassociate the existing stub from class.
   untag()->set_allocation_stub(Code::null());
+#endif  // defined(DART_PRECOMPILED_RUNTIME)
 }
 
 bool Class::IsDartFunctionClass() const {
diff --git a/runtime/vm/object.h b/runtime/vm/object.h
index b936691..6657bf0 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -1053,10 +1053,29 @@
   ScriptPtr script() const { return untag()->script(); }
   void set_script(const Script& value) const;
 
-  TokenPosition token_pos() const { return untag()->token_pos_; }
+  TokenPosition token_pos() const {
+#if defined(DART_PRECOMPILED_RUNTIME)
+    return TokenPosition::kNoSource;
+#else
+    return untag()->token_pos_;
+#endif  // defined(DART_PRECOMPILED_RUNTIME)
+  }
+
+#if !defined(DART_PRECOMPILED_RUNTIME)
   void set_token_pos(TokenPosition value) const;
-  TokenPosition end_token_pos() const { return untag()->end_token_pos_; }
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
+
+  TokenPosition end_token_pos() const {
+#if defined(DART_PRECOMPILED_RUNTIME)
+    return TokenPosition::kNoSource;
+#else
+    return untag()->end_token_pos_;
+#endif  // defined(DART_PRECOMPILED_RUNTIME)
+  }
+
+#if !defined(DART_PRECOMPILED_RUNTIME)
   void set_end_token_pos(TokenPosition value) const;
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
   int32_t SourceFingerprint() const;
 
@@ -1195,6 +1214,7 @@
   }
   void set_interfaces(const Array& value) const;
 
+#if !defined(PRODUCT) || !defined(DART_PRECOMPILED_RUNTIME)
   // Returns the list of classes directly implementing this class.
   GrowableObjectArrayPtr direct_implementors() const {
     DEBUG_ASSERT(
@@ -1204,9 +1224,14 @@
   GrowableObjectArrayPtr direct_implementors_unsafe() const {
     return untag()->direct_implementors();
   }
+#endif  // !defined(PRODUCT) || !defined(DART_PRECOMPILED_RUNTIME)
+
+#if !defined(DART_PRECOMPILED_RUNTIME)
   void set_direct_implementors(const GrowableObjectArray& implementors) const;
   void AddDirectImplementor(const Class& subclass, bool is_mixin) const;
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
+#if !defined(PRODUCT) || !defined(DART_PRECOMPILED_RUNTIME)
   // Returns the list of classes having this class as direct superclass.
   GrowableObjectArrayPtr direct_subclasses() const {
     DEBUG_ASSERT(
@@ -1216,8 +1241,12 @@
   GrowableObjectArrayPtr direct_subclasses_unsafe() const {
     return untag()->direct_subclasses();
   }
+#endif  // !defined(PRODUCT) || !defined(DART_PRECOMPILED_RUNTIME)
+
+#if !defined(DART_PRECOMPILED_RUNTIME)
   void set_direct_subclasses(const GrowableObjectArray& subclasses) const;
   void AddDirectSubclass(const Class& subclass) const;
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
   // Check if this class represents the class of null.
   bool IsNullClass() const { return id() == kNullCid; }
@@ -1438,8 +1467,10 @@
     StoreNonPointer(&untag()->num_native_fields_, value);
   }
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
   CodePtr allocation_stub() const { return untag()->allocation_stub(); }
   void set_allocation_stub(const Code& value) const;
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
   intptr_t kernel_offset() const {
 #if defined(DART_PRECOMPILED_RUNTIME)
@@ -1539,6 +1570,7 @@
   static ClassPtr NewPointerClass(intptr_t class_id,
                                   IsolateGroup* isolate_group);
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
   // Register code that has used CHA for optimization.
   // TODO(srdjan): Also register kind of CHA optimization (e.g.: leaf class,
   // leaf method, ...).
@@ -1555,6 +1587,7 @@
   // are finalized.
   ArrayPtr dependent_code() const;
   void set_dependent_code(const Array& array) const;
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
   bool TraceAllocation(IsolateGroup* isolate_group) const;
   void SetTraceAllocation(bool trace_allocation) const;
diff --git a/runtime/vm/program_visitor.cc b/runtime/vm/program_visitor.cc
index c5a7965..4bb663a 100644
--- a/runtime/vm/program_visitor.cc
+++ b/runtime/vm/program_visitor.cc
@@ -2,6 +2,8 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
+
 #include "vm/program_visitor.h"
 
 #include "vm/closure_functions_cache.h"
@@ -289,7 +291,6 @@
   walker.VisitWorklist();
 }
 
-#if !defined(DART_PRECOMPILED_RUNTIME)
 // A base class for deduplication of objects. T is the type of canonical objects
 // being stored, whereas S is a trait appropriate for a DirectChainedHashMap
 // based set containing those canonical objects.
@@ -1349,10 +1350,8 @@
   DedupInstructionsVisitor visitor(zone);
   WalkProgram(zone, isolate_group, &visitor);
 }
-#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
 void ProgramVisitor::Dedup(Thread* thread) {
-#if !defined(DART_PRECOMPILED_RUNTIME)
   auto const isolate_group = thread->isolate_group();
   StackZone stack_zone(thread);
   HANDLESCOPE(thread);
@@ -1394,7 +1393,6 @@
 
     DedupInstructions(zone, isolate_group);
   }
-#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 }
 
 #if defined(DART_PRECOMPILER)
@@ -1560,6 +1558,8 @@
   return visitor.hash();
 }
 
-#endif  // defined(DART_PRECOMPILED_RUNTIME)
+#endif  // defined(DART_PRECOMPILER)
 
 }  // namespace dart
+
+#endif  // defined(DART_PRECOMPILED_RUNTIME)
diff --git a/runtime/vm/program_visitor.h b/runtime/vm/program_visitor.h
index b310625..fa57326 100644
--- a/runtime/vm/program_visitor.h
+++ b/runtime/vm/program_visitor.h
@@ -5,6 +5,8 @@
 #ifndef RUNTIME_VM_PROGRAM_VISITOR_H_
 #define RUNTIME_VM_PROGRAM_VISITOR_H_
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
+
 #include "vm/allocation.h"
 
 namespace dart {
@@ -104,7 +106,6 @@
 #endif
 
  private:
-#if !defined(DART_PRECOMPILED_RUNTIME)
   static void BindStaticCalls(Zone* zone, IsolateGroup* isolate_group);
   static void ShareMegamorphicBuckets(Zone* zone, IsolateGroup* isolate_group);
   static void NormalizeAndDedupCompressedStackMaps(Zone* zone,
@@ -119,9 +120,10 @@
   static void DedupCodeSourceMaps(Zone* zone, IsolateGroup* isolate_group);
   static void DedupLists(Zone* zone, IsolateGroup* isolate_group);
   static void DedupInstructions(Zone* zone, IsolateGroup* isolate_group);
-#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 };
 
 }  // namespace dart
 
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
+
 #endif  // RUNTIME_VM_PROGRAM_VISITOR_H_
diff --git a/runtime/vm/raw_object.h b/runtime/vm/raw_object.h
index 7753a7a..308284a 100644
--- a/runtime/vm/raw_object.h
+++ b/runtime/vm/raw_object.h
@@ -905,7 +905,7 @@
 
   VISIT_FROM(CompressedObjectPtr, name)
   COMPRESSED_POINTER_FIELD(StringPtr, name)
-  COMPRESSED_POINTER_FIELD(StringPtr, user_name)
+  NOT_IN_PRODUCT(COMPRESSED_POINTER_FIELD(StringPtr, user_name))
   COMPRESSED_POINTER_FIELD(ArrayPtr, functions)
   COMPRESSED_POINTER_FIELD(ArrayPtr, functions_hash_table)
   COMPRESSED_POINTER_FIELD(ArrayPtr, fields)
@@ -922,26 +922,49 @@
   COMPRESSED_POINTER_FIELD(TypePtr, declaration_type)
   // Cache for dispatcher functions.
   COMPRESSED_POINTER_FIELD(ArrayPtr, invocation_dispatcher_cache)
-  // Stub code for allocation of instances.
-  COMPRESSED_POINTER_FIELD(CodePtr, allocation_stub)
+
+#if !defined(PRODUCT) || !defined(DART_PRECOMPILED_RUNTIME)
   // Array of Class.
   COMPRESSED_POINTER_FIELD(GrowableObjectArrayPtr, direct_implementors)
   // Array of Class.
   COMPRESSED_POINTER_FIELD(GrowableObjectArrayPtr, direct_subclasses)
+#endif  // !defined(PRODUCT) || !defined(DART_PRECOMPILED_RUNTIME)
+
+#if !defined(DART_PRECOMPILED_RUNTIME)
+  // Stub code for allocation of instances.
+  COMPRESSED_POINTER_FIELD(CodePtr, allocation_stub)
   // CHA optimized codes.
   COMPRESSED_POINTER_FIELD(ArrayPtr, dependent_code)
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
+
+#if defined(DART_PRECOMPILED_RUNTIME)
+#if defined(PRODUCT)
+  VISIT_TO(CompressedObjectPtr, invocation_dispatcher_cache)
+#else
+  VISIT_TO(CompressedObjectPtr, direct_subclasses)
+#endif  // defined(PRODUCT)
+#else
   VISIT_TO(CompressedObjectPtr, dependent_code)
+#endif  // defined(DART_PRECOMPILED_RUNTIME)
+
   CompressedObjectPtr* to_snapshot(Snapshot::Kind kind) {
     switch (kind) {
       case Snapshot::kFullAOT:
 #if defined(PRODUCT)
-        return reinterpret_cast<CompressedObjectPtr*>(&allocation_stub_);
-#endif
+        return reinterpret_cast<CompressedObjectPtr*>(
+            &invocation_dispatcher_cache_);
+#else
+        return reinterpret_cast<CompressedObjectPtr*>(&direct_subclasses_);
+#endif  // defined(PRODUCT)
       case Snapshot::kFull:
       case Snapshot::kFullCore:
-        return reinterpret_cast<CompressedObjectPtr*>(&direct_subclasses_);
+#if !defined(DART_PRECOMPILED_RUNTIME)
+        return reinterpret_cast<CompressedObjectPtr*>(&allocation_stub_);
+#endif
       case Snapshot::kFullJIT:
+#if !defined(DART_PRECOMPILED_RUNTIME)
         return reinterpret_cast<CompressedObjectPtr*>(&dependent_code_);
+#endif
       case Snapshot::kMessage:
       case Snapshot::kNone:
       case Snapshot::kInvalid:
@@ -951,8 +974,8 @@
     return NULL;
   }
 
-  TokenPosition token_pos_;
-  TokenPosition end_token_pos_;
+  NOT_IN_PRECOMPILED(TokenPosition token_pos_);
+  NOT_IN_PRECOMPILED(TokenPosition end_token_pos_);
 
   classid_t id_;                // Class Id, also index in the class table.
   int16_t num_type_arguments_;  // Number of type arguments in flattened vector.
@@ -977,9 +1000,7 @@
 
   // Offset of the next instance field (target).
   int32_t target_next_field_offset_in_words_;
-#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
-#if !defined(DART_PRECOMPILED_RUNTIME)
   uint32_t kernel_offset_;
 #endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
diff --git a/runtime/vm/raw_object_fields.cc b/runtime/vm/raw_object_fields.cc
index 7329337..faea10f 100644
--- a/runtime/vm/raw_object_fields.cc
+++ b/runtime/vm/raw_object_fields.cc
@@ -10,7 +10,6 @@
 
 #define COMMON_CLASSES_AND_FIELDS(F)                                           \
   F(Class, name_)                                                              \
-  F(Class, user_name_)                                                         \
   F(Class, functions_)                                                         \
   F(Class, functions_hash_table_)                                              \
   F(Class, fields_)                                                            \
@@ -23,10 +22,6 @@
   F(Class, constants_)                                                         \
   F(Class, declaration_type_)                                                  \
   F(Class, invocation_dispatcher_cache_)                                       \
-  F(Class, allocation_stub_)                                                   \
-  F(Class, direct_implementors_)                                               \
-  F(Class, direct_subclasses_)                                                 \
-  F(Class, dependent_code_)                                                    \
   F(PatchClass, patched_class_)                                                \
   F(PatchClass, origin_class_)                                                 \
   F(PatchClass, script_)                                                       \
@@ -197,15 +192,24 @@
 
 #define AOT_CLASSES_AND_FIELDS(F)
 
+#define AOT_NON_PRODUCT_CLASSES_AND_FIELDS(F)                                  \
+  F(Class, direct_implementors_)                                               \
+  F(Class, direct_subclasses_)
+
 #define JIT_CLASSES_AND_FIELDS(F)                                              \
+  F(Class, allocation_stub_)                                                   \
+  F(Class, dependent_code_)                                                    \
+  F(Class, direct_implementors_)                                               \
+  F(Class, direct_subclasses_)                                                 \
   F(Code, active_instructions_)                                                \
   F(Code, deopt_info_array_)                                                   \
   F(Code, static_calls_target_table_)                                          \
   F(ICData, receivers_static_type_)                                            \
   F(Function, unoptimized_code_)                                               \
-  F(Field, type_test_cache_)                                                   \
+  F(Field, type_test_cache_)
 
 #define NON_PRODUCT_CLASSES_AND_FIELDS(F)                                      \
+  F(Class, user_name_)                                                         \
   F(ReceivePort, debug_name_)                                                  \
   F(ReceivePort, allocation_location_)
 
@@ -240,6 +244,9 @@
 
 #if defined(DART_PRECOMPILED_RUNTIME)
     AOT_CLASSES_AND_FIELDS(DEFINE_OFFSETS_TABLE_ENTRY)
+#if !defined(PRODUCT)
+    AOT_NON_PRODUCT_CLASSES_AND_FIELDS(DEFINE_OFFSETS_TABLE_ENTRY)
+#endif
 #else
     JIT_CLASSES_AND_FIELDS(DEFINE_OFFSETS_TABLE_ENTRY)
 #endif
diff --git a/runtime/vm/stub_code.cc b/runtime/vm/stub_code.cc
index a78d1b0..0afa895 100644
--- a/runtime/vm/stub_code.cc
+++ b/runtime/vm/stub_code.cc
@@ -162,7 +162,6 @@
   }
   return static_calls_table.ptr();
 }
-#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
 CodePtr StubCode::GetAllocationStubForClass(const Class& cls) {
   Thread* thread = Thread::Current();
@@ -179,7 +178,6 @@
     return object_store->allocate_unhandled_exception_stub();
   }
   Code& stub = Code::Handle(zone, cls.allocation_stub());
-#if !defined(DART_PRECOMPILED_RUNTIME)
   if (stub.IsNull()) {
     compiler::ObjectPoolBuilder object_pool_builder;
     Precompiler* precompiler = Precompiler::Instance();
@@ -247,7 +245,6 @@
     }
 #endif  // !PRODUCT
   }
-#endif  // !defined(DART_PRECOMPILED_RUNTIME)
   return stub.ptr();
 }
 
@@ -286,6 +283,7 @@
   UNREACHABLE();
   return Code::null();
 }
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
 #if !defined(TARGET_ARCH_IA32)
 CodePtr StubCode::GetBuildMethodExtractorStub(
diff --git a/runtime/vm/stub_code.h b/runtime/vm/stub_code.h
index a946cd5..6dcedc5 100644
--- a/runtime/vm/stub_code.h
+++ b/runtime/vm/stub_code.h
@@ -61,8 +61,10 @@
   VM_STUB_CODE_LIST(STUB_CODE_ACCESSOR);
 #undef STUB_CODE_ACCESSOR
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
   static CodePtr GetAllocationStubForClass(const Class& cls);
   static CodePtr GetAllocationStubForTypedData(classid_t class_id);
+#endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
 #if !defined(TARGET_ARCH_IA32)
   static CodePtr GetBuildMethodExtractorStub(compiler::ObjectPoolBuilder* pool);