[VM] Remove unused _Random._A field in Dart sources and make constant in C++ code instead

Issue https://github.com/dart-lang/sdk/issues/33185

Change-Id: I256a66ebf81d4433bded15f19b4147327df9b588
Reviewed-on: https://dart-review.googlesource.com/56329
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
diff --git a/pkg/vm/lib/kernel_front_end.dart b/pkg/vm/lib/kernel_front_end.dart
index 7d3cec8..7e7762f 100644
--- a/pkg/vm/lib/kernel_front_end.dart
+++ b/pkg/vm/lib/kernel_front_end.dart
@@ -159,8 +159,6 @@
     final typeEnvironment =
         new TypeEnvironment(coreTypes, hierarchy, strongMode: strongMode);
 
-    // NOTE: Currently we keep fields, because there are certain constant
-    // fields which the VM accesses (e.g. `_Random._A` needs to be preserved).
     // TODO(kustermann): We should use the entrypoints manifest to find out
     // which fields need to be preserved and remove the rest.
     constants.transformComponent(component, vmConstants,
diff --git a/pkg/vm/lib/transformations/type_flow/entry_points_extra.json b/pkg/vm/lib/transformations/type_flow/entry_points_extra.json
index 0ff8ba4..e739bb9 100644
--- a/pkg/vm/lib/transformations/type_flow/entry_points_extra.json
+++ b/pkg/vm/lib/transformations/type_flow/entry_points_extra.json
@@ -173,12 +173,6 @@
       "library": "dart:async",
       "class": "_AsyncStarStreamController",
       "action": "create-instance"
-    },
-    {
-      "library": "dart:math",
-      "class": "_Random",
-      "name": "_A",
-      "action": "get"
     }
   ]
 }
diff --git a/runtime/lib/math_patch.dart b/runtime/lib/math_patch.dart
index 793b10b..8888042 100644
--- a/runtime/lib/math_patch.dart
+++ b/runtime/lib/math_patch.dart
@@ -189,6 +189,7 @@
   // The constant A is selected from "Numerical Recipes 3rd Edition" p.348 B1.
 
   // Implements:
+  //   const _A = 0xffffda61;
   //   var state =
   //       ((_A * (_state[_kSTATE_LO])) + _state[_kSTATE_HI]) & ((1 << 64) - 1);
   //   _state[_kSTATE_LO] = state & ((1 << 32) - 1);
@@ -233,8 +234,6 @@
   static const _POW2_53_D = 1.0 * (1 << 53);
   static const _POW2_27_D = 1.0 * (1 << 27);
 
-  static const _A = 0xffffda61;
-
   // Use a singleton Random object to get a new seed if no seed was passed.
   static var _prng = new _Random._withState(_initialSeed());
 
diff --git a/runtime/vm/compiler/intrinsifier.h b/runtime/vm/compiler/intrinsifier.h
index 2dbc111..bf2ec2a 100644
--- a/runtime/vm/compiler/intrinsifier.h
+++ b/runtime/vm/compiler/intrinsifier.h
@@ -36,6 +36,10 @@
   static void IntrinsicCallEpilogue(Assembler* assembler);
 
  private:
+  // The "_A" value used in the intrinsification of
+  // `runtime/lib/math_patch.dart:_Random._nextState()`
+  static const int64_t kRandomAValue = 0xffffda61;
+
   static bool CanIntrinsify(const Function& function);
 
 #define DECLARE_FUNCTION(class_name, function_name, enum_name, type, fp)       \
diff --git a/runtime/vm/compiler/intrinsifier_arm.cc b/runtime/vm/compiler/intrinsifier_arm.cc
index 9b0c63b..201306d 100644
--- a/runtime/vm/compiler/intrinsifier_arm.cc
+++ b/runtime/vm/compiler/intrinsifier_arm.cc
@@ -1520,17 +1520,7 @@
   const Field& state_field = Field::ZoneHandle(
       random_class.LookupInstanceFieldAllowPrivate(Symbols::_state()));
   ASSERT(!state_field.IsNull());
-  const Field& random_A_field = Field::ZoneHandle(
-      random_class.LookupStaticFieldAllowPrivate(Symbols::_A()));
-  ASSERT(!random_A_field.IsNull());
-  ASSERT(random_A_field.is_const());
-  Instance& a_value = Instance::Handle(random_A_field.StaticValue());
-  if (a_value.raw() == Object::sentinel().raw() ||
-      a_value.raw() == Object::transition_sentinel().raw()) {
-    random_A_field.EvaluateInitializer();
-    a_value = random_A_field.StaticValue();
-  }
-  const int64_t a_int_value = Integer::Cast(a_value).AsInt64Value();
+  const int64_t a_int_value = Intrinsifier::kRandomAValue;
   // 'a_int_value' is a mask.
   ASSERT(Utils::IsUint(32, a_int_value));
   int32_t a_int32_value = static_cast<int32_t>(a_int_value);
diff --git a/runtime/vm/compiler/intrinsifier_arm64.cc b/runtime/vm/compiler/intrinsifier_arm64.cc
index 4598536..d14b824 100644
--- a/runtime/vm/compiler/intrinsifier_arm64.cc
+++ b/runtime/vm/compiler/intrinsifier_arm64.cc
@@ -1579,17 +1579,7 @@
   const Field& state_field = Field::ZoneHandle(
       random_class.LookupInstanceFieldAllowPrivate(Symbols::_state()));
   ASSERT(!state_field.IsNull());
-  const Field& random_A_field = Field::ZoneHandle(
-      random_class.LookupStaticFieldAllowPrivate(Symbols::_A()));
-  ASSERT(!random_A_field.IsNull());
-  ASSERT(random_A_field.is_const());
-  Instance& a_value = Instance::Handle(random_A_field.StaticValue());
-  if (a_value.raw() == Object::sentinel().raw() ||
-      a_value.raw() == Object::transition_sentinel().raw()) {
-    random_A_field.EvaluateInitializer();
-    a_value = random_A_field.StaticValue();
-  }
-  const int64_t a_int_value = Integer::Cast(a_value).AsInt64Value();
+  const int64_t a_int_value = Intrinsifier::kRandomAValue;
 
   // Receiver.
   __ ldr(R0, Address(SP, 0 * kWordSize));
diff --git a/runtime/vm/compiler/intrinsifier_ia32.cc b/runtime/vm/compiler/intrinsifier_ia32.cc
index 7727717..2e46b55 100644
--- a/runtime/vm/compiler/intrinsifier_ia32.cc
+++ b/runtime/vm/compiler/intrinsifier_ia32.cc
@@ -1588,20 +1588,11 @@
   const Field& state_field = Field::ZoneHandle(
       random_class.LookupInstanceFieldAllowPrivate(Symbols::_state()));
   ASSERT(!state_field.IsNull());
-  const Field& random_A_field = Field::ZoneHandle(
-      random_class.LookupStaticFieldAllowPrivate(Symbols::_A()));
-  ASSERT(!random_A_field.IsNull());
-  ASSERT(random_A_field.is_const());
-  Instance& a_value = Instance::Handle(random_A_field.StaticValue());
-  if (a_value.raw() == Object::sentinel().raw() ||
-      a_value.raw() == Object::transition_sentinel().raw()) {
-    random_A_field.EvaluateInitializer();
-    a_value = random_A_field.StaticValue();
-  }
-  const int64_t a_int_value = Integer::Cast(a_value).AsInt64Value();
+  const int64_t a_int_value = Intrinsifier::kRandomAValue;
   // 'a_int_value' is a mask.
   ASSERT(Utils::IsUint(32, a_int_value));
   int32_t a_int32_value = static_cast<int32_t>(a_int_value);
+
   // Receiver.
   __ movl(EAX, Address(ESP, +1 * kWordSize));
   // Field '_state'.
diff --git a/runtime/vm/compiler/intrinsifier_x64.cc b/runtime/vm/compiler/intrinsifier_x64.cc
index 1e2574c..a3a0c9b 100644
--- a/runtime/vm/compiler/intrinsifier_x64.cc
+++ b/runtime/vm/compiler/intrinsifier_x64.cc
@@ -1496,17 +1496,8 @@
   const Field& state_field = Field::ZoneHandle(
       random_class.LookupInstanceFieldAllowPrivate(Symbols::_state()));
   ASSERT(!state_field.IsNull());
-  const Field& random_A_field = Field::ZoneHandle(
-      random_class.LookupStaticFieldAllowPrivate(Symbols::_A()));
-  ASSERT(!random_A_field.IsNull());
-  ASSERT(random_A_field.is_const());
-  Instance& a_value = Instance::Handle(random_A_field.StaticValue());
-  if (a_value.raw() == Object::sentinel().raw() ||
-      a_value.raw() == Object::transition_sentinel().raw()) {
-    random_A_field.EvaluateInitializer();
-    a_value = random_A_field.StaticValue();
-  }
-  const int64_t a_int_value = Integer::Cast(a_value).AsInt64Value();
+  const int64_t a_int_value = Intrinsifier::kRandomAValue;
+
   // Receiver.
   __ movq(RAX, Address(RSP, +1 * kWordSize));
   // Field '_state'.
diff --git a/runtime/vm/symbols.h b/runtime/vm/symbols.h
index fdd9ee4..a68bce5 100644
--- a/runtime/vm/symbols.h
+++ b/runtime/vm/symbols.h
@@ -387,7 +387,6 @@
   V(ExternalName, "ExternalName")                                              \
   V(_Random, "_Random")                                                        \
   V(_state, "_state")                                                          \
-  V(_A, "_A")                                                                  \
   V(_stackTrace, "_stackTrace")                                                \
   V(_SpecialTypeMirror, "_SpecialTypeMirror")                                  \
   V(_LocalClassMirror, "_LocalClassMirror")                                    \