// Copyright 2019 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef TOOLS_CLANG_STACK_MAPS_OBJECTS_H_ #define TOOLS_CLANG_STACK_MAPS_OBJECTS_H_ #include #define GC_AS __attribute__((address_space(1))) // This should be used only when finer control is needed to prevent statepoint // insertion. It must not be used on functions which will have a pointer on the // stack across a GC. It should be used very carefully as it overrides the // default statepointing mechanism. #define NO_STATEPOINT \ __attribute__((noinline)) __attribute__((annotate("no-statepoint"))) using Address = void GC_AS*; // A HeapObject is just a heap allocated long integer. This is all that is // necessary to show precise stack scanning in practise and greatly simplifies // the implementation. class HeapObject { public: NO_STATEPOINT HeapObject(long data) : data(data) {} long data; }; template class Handle { public: static NO_STATEPOINT Handle New(T* obj_ptr) { // We have to break the style guide here and do a C style cast because it // guarantees an address space cast takes place in the IR. reinterpret_cast // will fail to compile when address space qualifiers do not match. auto gcptr = (Address GC_AS*)obj_ptr; return Handle(gcptr); } T operator*() const { long data = *(long GC_AS*)address; return HeapObject(data); } private: Address address; Handle(Address address) : address(address) {} }; #endif // TOOLS_CLANG_STACK_MAPS_OBJECTS_H_