2013-01-18 00:34:20 +00:00
|
|
|
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
2011-10-05 05:20:07 +00:00
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
2016-10-26 07:26:03 +00:00
|
|
|
#ifndef RUNTIME_VM_ALLOCATION_H_
|
|
|
|
#define RUNTIME_VM_ALLOCATION_H_
|
2011-10-05 05:20:07 +00:00
|
|
|
|
2017-02-23 20:40:48 +00:00
|
|
|
#include "platform/allocation.h"
|
2012-01-16 12:28:10 +00:00
|
|
|
#include "platform/assert.h"
|
|
|
|
#include "vm/globals.h"
|
2011-10-05 05:20:07 +00:00
|
|
|
|
|
|
|
namespace dart {
|
|
|
|
|
2011-11-10 21:08:18 +00:00
|
|
|
// Forward declarations.
|
2019-01-11 20:47:10 +00:00
|
|
|
class ThreadState;
|
2019-01-25 16:45:13 +00:00
|
|
|
class Zone;
|
2011-11-10 21:08:18 +00:00
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
// Stack resources subclass from this base class. The VM will ensure that the
|
|
|
|
// destructors of these objects are called before the stack is unwound past the
|
|
|
|
// objects location on the stack. Use stack resource objects if objects
|
|
|
|
// need to be destroyed even in the case of exceptions when a Longjump is done
|
|
|
|
// to a stack frame above the frame where these objects were allocated.
|
|
|
|
class StackResource {
|
|
|
|
public:
|
2019-01-11 20:47:10 +00:00
|
|
|
explicit StackResource(ThreadState* thread) : thread_(NULL), previous_(NULL) {
|
2015-07-09 18:22:26 +00:00
|
|
|
Init(thread);
|
2012-04-06 18:00:51 +00:00
|
|
|
}
|
|
|
|
|
2015-10-06 17:17:12 +00:00
|
|
|
virtual ~StackResource();
|
2012-04-06 18:00:51 +00:00
|
|
|
|
2015-07-09 18:22:26 +00:00
|
|
|
// The thread that owns this resource.
|
2019-01-11 20:47:10 +00:00
|
|
|
ThreadState* thread() const { return thread_; }
|
2011-11-10 21:08:18 +00:00
|
|
|
|
2015-07-31 19:57:19 +00:00
|
|
|
// Destroy stack resources of thread until top exit frame.
|
2019-01-11 20:47:10 +00:00
|
|
|
static void Unwind(ThreadState* thread) { UnwindAbove(thread, NULL); }
|
2015-07-31 19:57:19 +00:00
|
|
|
// Destroy stack resources of thread above new_top, exclusive.
|
2019-01-11 20:47:10 +00:00
|
|
|
static void UnwindAbove(ThreadState* thread, StackResource* new_top);
|
2015-02-18 23:21:32 +00:00
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
private:
|
2019-01-11 20:47:10 +00:00
|
|
|
void Init(ThreadState* thread);
|
2015-07-09 18:22:26 +00:00
|
|
|
|
2019-01-11 20:47:10 +00:00
|
|
|
ThreadState* thread_;
|
2011-10-05 05:20:07 +00:00
|
|
|
StackResource* previous_;
|
|
|
|
|
2014-03-13 20:38:24 +00:00
|
|
|
DISALLOW_ALLOCATION();
|
2011-11-21 21:07:40 +00:00
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(StackResource);
|
2011-10-05 05:20:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Zone allocated objects cannot be individually deallocated, but have
|
|
|
|
// to rely on the destructor of Zone which is called when the Zone
|
|
|
|
// goes out of scope to reclaim memory.
|
|
|
|
class ZoneAllocated {
|
|
|
|
public:
|
2016-11-08 21:54:47 +00:00
|
|
|
ZoneAllocated() {}
|
2011-10-05 05:20:07 +00:00
|
|
|
|
|
|
|
// Implicitly allocate the object in the current zone.
|
|
|
|
void* operator new(uword size);
|
|
|
|
|
2015-01-15 21:29:57 +00:00
|
|
|
// Allocate the object in the given zone, which must be the current zone.
|
|
|
|
void* operator new(uword size, Zone* zone);
|
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
// Ideally, the delete operator should be protected instead of
|
|
|
|
// public, but unfortunately the compiler sometimes synthesizes
|
|
|
|
// (unused) destructors for classes derived from ZoneObject, which
|
|
|
|
// require the operator to be visible. MSVC requires the delete
|
|
|
|
// operator to be public.
|
|
|
|
|
|
|
|
// Disallow explicit deallocation of nodes. Nodes can only be
|
|
|
|
// deallocated by invoking DeleteAll() on the zone they live in.
|
|
|
|
void operator delete(void* pointer) { UNREACHABLE(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ZoneAllocated);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dart
|
|
|
|
|
2016-10-26 07:26:03 +00:00
|
|
|
#endif // RUNTIME_VM_ALLOCATION_H_
|