objects.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef TOOLS_CLANG_STACK_MAPS_OBJECTS_H_
  5. #define TOOLS_CLANG_STACK_MAPS_OBJECTS_H_
  6. #include <stdint.h>
  7. #define GC_AS __attribute__((address_space(1)))
  8. // This should be used only when finer control is needed to prevent statepoint
  9. // insertion. It must not be used on functions which will have a pointer on the
  10. // stack across a GC. It should be used very carefully as it overrides the
  11. // default statepointing mechanism.
  12. #define NO_STATEPOINT \
  13. __attribute__((noinline)) __attribute__((annotate("no-statepoint")))
  14. using Address = void GC_AS*;
  15. // A HeapObject is just a heap allocated long integer. This is all that is
  16. // necessary to show precise stack scanning in practise and greatly simplifies
  17. // the implementation.
  18. class HeapObject {
  19. public:
  20. NO_STATEPOINT HeapObject(long data) : data(data) {}
  21. long data;
  22. };
  23. template <typename T>
  24. class Handle {
  25. public:
  26. static NO_STATEPOINT Handle<T> New(T* obj_ptr) {
  27. // We have to break the style guide here and do a C style cast because it
  28. // guarantees an address space cast takes place in the IR. reinterpret_cast
  29. // will fail to compile when address space qualifiers do not match.
  30. auto gcptr = (Address GC_AS*)obj_ptr;
  31. return Handle<T>(gcptr);
  32. }
  33. T operator*() const {
  34. long data = *(long GC_AS*)address;
  35. return HeapObject(data);
  36. }
  37. private:
  38. Address address;
  39. Handle<T>(Address address) : address(address) {}
  40. };
  41. #endif // TOOLS_CLANG_STACK_MAPS_OBJECTS_H_