// Copyright 2012 the V8 project 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 V8_ZONE_ZONE_H_ #define V8_ZONE_ZONE_H_ #include <limits> #include <memory> #include <type_traits> #include <utility> #include "src/base/logging.h" #include "src/base/vector.h" #include "src/common/globals.h" #include "src/zone/accounting-allocator.h" #include "src/zone/type-stats.h" #include "src/zone/zone-segment.h" #include "src/zone/zone-type-traits.h" #ifndef ZONE_NAME #define ZONE_NAME … #endif namespace v8 { namespace internal { // The Zone supports very fast allocation of small chunks of // memory. The chunks cannot be deallocated individually, but instead // the Zone supports deallocating all chunks in one fast // operation. The Zone is used to hold temporary data structures like // the abstract syntax tree, which is deallocated after compilation. // // Note: There is no need to initialize the Zone; the first time an // allocation is attempted, a segment of memory will be requested // through the allocator. // // Note: The implementation is inherently not thread safe. Do not use // from multi-threaded code. class V8_EXPORT_PRIVATE Zone final { … }; // Similar to the HandleScope, the ZoneScope defines a region of validity for // zone memory. All memory allocated in the given Zone during the scope's // lifetime is freed when the scope is destructed, i.e. the Zone is reset to // the state it was in when the scope was created. class ZoneScope final { … }; // ZoneObject is an abstraction that helps define classes of objects // allocated in the Zone. Use it as a base class; see ast.h. class ZoneObject { … }; // The ZoneAllocationPolicy is used to specialize generic data // structures to allocate themselves and their elements in the Zone. class ZoneAllocationPolicy { … }; } // namespace internal } // namespace v8 // The accidential old-style pattern // new (zone) SomeObject(...) // now produces compilation error. The proper way of allocating objects in // Zones looks like this: // zone->New<SomeObject>(...) void* operator new(size_t, v8::internal::Zone*) = delete; // See explanation. void operator delete(void*, v8::internal::Zone*) = delete; // See explanation. #endif // V8_ZONE_ZONE_H_