[vm] Clean up New() methods of Dart classes.

Goals of this CL, a followup to 2f63acea22:

* Ensure that X::New() depends on the initialization guarantees of
  Object::Allocate<X>(...):

  * Ptr fields are guaranteed to be initialized to Object::null().
  * Non-Ptr fields are guaranteed to be zero-initialized.

  In cases where the only uses of the allocated object before return
  was to perform unnecessary field assignments, X::New() just simply
  returns the result of Object::Allocate<X>(...).

  Otherwise, the old now-unnecessary assignments have been changed
  into ASSERTs so that they will be checked in DEBUG mode.

* Ensure that NoSafepointScopes are entered in X::New() only when
  necessary (e.g., to ensure fields used to calculate to(...)
  are properly set before being seen by pointer visitors as the GC
  may run when outside a NoSafepointScope).

  In particular, the often occurring pattern:

  auto& result = X::Handle();
  {
    auto raw = Object::Allocate<X>(...);
    NoSafepointScope no_safepoint;
    result = raw;
  }
  ...

  has been replaced with:

  const auto& result = X::Handle(Object::Allocate<X>(...));

* If a handle was allocated, the only uses of that handle before
  returning must be performed under a NoSafepointScope, and the same
  operations can be done directly on the object pointer, then do so
  and remove the unnecessary handle allocation.

Notable changes outside the above:

* Swapped ObjectPool::EntryType::{kImmediate,kTaggedObject} so that
  kImmediate has value 0, since Object::Allocate<ObjectPool>(len)
  zero-initializes the payload and without this change,
  ObjectPool::New() must set the entry types manually.

* Removed the old static ArrayPtr cached_array_ field on
  SubtypeTestCache as well as SubtypeTestCache::{Init,Cleanup} and
  instead added Object::empty_subtype_test_cache_array().

* Removed the no-arg Closure::New() method, which is never used.

* Inlined the no-arg Script::New() method into its only caller,
  one of the other Script::New() overloads.

TEST=ci

Issue: https://github.com/dart-lang/sdk/issues/52876
Change-Id: I079b4c9f73c7d2c0146c30cf2cd570b91a1ecf36
Cq-Include-Trybots: luci.dart.try:vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-linux-release-x64-try,vm-aot-linux-product-x64-try,vm-aot-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-ffi-qemu-linux-release-riscv64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313120
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
5 files changed
tree: da7a9068331297a66a2f0cf581c5859c39de92b6
  1. .dart_tool/
  2. .github/
  3. benchmarks/
  4. build/
  5. docs/
  6. pkg/
  7. runtime/
  8. samples/
  9. sdk/
  10. tests/
  11. third_party/
  12. tools/
  13. utils/
  14. .clang-format
  15. .gitattributes
  16. .gitconfig
  17. .gitignore
  18. .gn
  19. .mailmap
  20. .style.yapf
  21. .vpython
  22. AUTHORS
  23. BUILD.gn
  24. CHANGELOG.md
  25. codereview.settings
  26. CONTRIBUTING.md
  27. DEPS
  28. LICENSE
  29. OWNERS
  30. PATENT_GRANT
  31. PRESUBMIT.py
  32. README.dart-sdk
  33. README.md
  34. sdk.code-workspace
  35. sdk_args.gni
  36. SECURITY.md
  37. WATCHLISTS
README.md

Dart

A client-optimized language for fast apps on any platform

Dart is:

  • Optimized for UI: Develop with a programming language specialized around the needs of user interface creation.

  • Productive: Make changes iteratively: use hot reload to see the result instantly in your running app.

  • Fast on all platforms: Compile to ARM & x64 machine code for mobile, desktop, and backend. Or compile to JavaScript for the web.

Dart's flexible compiler technology lets you run Dart code in different ways, depending on your target platform and goals:

  • Dart Native: For programs targeting devices (mobile, desktop, server, and more), Dart Native includes both a Dart VM with JIT (just-in-time) compilation and an AOT (ahead-of-time) compiler for producing machine code.

  • Dart Web: For programs targeting the web, Dart Web includes both a development time compiler (dartdevc) and a production time compiler (dart2js).

Dart platforms illustration

License & patents

Dart is free and open source.

See LICENSE and PATENT_GRANT.

Using Dart

Visit dart.dev to learn more about the language, tools, and to find codelabs.

Browse pub.dev for more packages and libraries contributed by the community and the Dart team.

Our API reference documentation is published at api.dart.dev, based on the stable release. (We also publish docs from our beta and dev channels, as well as from the primary development branch).

Building Dart

If you want to build Dart yourself, here is a guide to getting the source, preparing your machine to build the SDK, and building.

There are more documents on our wiki.

Contributing to Dart

The easiest way to contribute to Dart is to file issues.

You can also contribute patches, as described in Contributing.