blob: ea3633c56225549f72b26a30df05b3b93dc4fd2b [file] [log] [blame]
// 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.
#include <stdint.h>
#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.
__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 {
NO_STATEPOINT HeapObject(long data) : data(data) {}
long data;
template <typename T>
class Handle {
static NO_STATEPOINT Handle<T> 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<T>(gcptr);
T operator*() const {
long data = *(long GC_AS*)address;
return HeapObject(data);
Address address;
Handle<T>(Address address) : address(address) {}