Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Unified Diff: src/zone.h

Issue 924453002: Fix invalid use of int in Zone. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Windows again... Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/typing.h ('k') | src/zone.cc » ('j') | src/zone.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/zone.h
diff --git a/src/zone.h b/src/zone.h
index da657155fe28e8e832a1a9c440feeaaa9b7ce813..a3511cdaa4036b0f93f2b4a27bcfa648554eb5f1 100644
--- a/src/zone.h
+++ b/src/zone.h
@@ -40,12 +40,11 @@ class Zone FINAL {
// Allocate 'size' bytes of memory in the Zone; expands the Zone by
// allocating new segments of memory on demand using malloc().
- void* New(int size);
+ void* New(size_t size);
template <typename T>
- T* NewArray(int length) {
- DCHECK(std::numeric_limits<int>::max() / static_cast<int>(sizeof(T)) >
- length);
+ T* NewArray(size_t length) {
+ DCHECK_LT(length, std::numeric_limits<size_t>::max() / sizeof(T));
return static_cast<T*>(New(length * sizeof(T)));
}
@@ -63,51 +62,51 @@ class Zone FINAL {
return segment_bytes_allocated_ > kExcessLimit;
}
- unsigned allocation_size() const { return allocation_size_; }
+ size_t allocation_size() const { return allocation_size_; }
private:
// All pointers returned from New() have this alignment. In addition, if the
// object being allocated has a size that is divisible by 8 then its alignment
// will be 8. ASan requires 8-byte alignment.
#ifdef V8_USE_ADDRESS_SANITIZER
- static const int kAlignment = 8;
+ static const size_t kAlignment = 8;
STATIC_ASSERT(kPointerSize <= 8);
#else
- static const int kAlignment = kPointerSize;
+ static const size_t kAlignment = kPointerSize;
#endif
// Never allocate segments smaller than this size in bytes.
- static const int kMinimumSegmentSize = 8 * KB;
+ static const size_t kMinimumSegmentSize = 8 * KB;
// Never allocate segments larger than this size in bytes.
- static const int kMaximumSegmentSize = 1 * MB;
+ static const size_t kMaximumSegmentSize = 1 * MB;
// Never keep segments larger than this size in bytes around.
- static const int kMaximumKeptSegmentSize = 64 * KB;
+ static const size_t kMaximumKeptSegmentSize = 64 * KB;
// Report zone excess when allocation exceeds this limit.
- static const int kExcessLimit = 256 * MB;
+ static const size_t kExcessLimit = 256 * MB;
// The number of bytes allocated in this zone so far.
- unsigned allocation_size_;
+ size_t allocation_size_;
// The number of bytes allocated in segments. Note that this number
// includes memory allocated from the OS but not yet allocated from
// the zone.
- int segment_bytes_allocated_;
+ size_t segment_bytes_allocated_;
// Expand the Zone to hold at least 'size' more bytes and allocate
// the bytes. Returns the address of the newly allocated chunk of
// memory in the Zone. Should only be called if there isn't enough
// room in the Zone already.
- Address NewExpand(int size);
+ Address NewExpand(size_t size);
// Creates a new segment, sets it size, and pushes it to the front
// of the segment chain. Returns the new segment.
- inline Segment* NewSegment(int size);
+ inline Segment* NewSegment(size_t size);
// Deletes the given segment. Does not touch the segment chain.
- inline void DeleteSegment(Segment* segment, int size);
+ inline void DeleteSegment(Segment* segment, size_t size);
// The free region in the current (front) segment is represented as
// the half-open interval [position, limit). The 'position' variable
@@ -124,9 +123,7 @@ class Zone FINAL {
class ZoneObject {
public:
// Allocate a new ZoneObject of 'size' bytes in the Zone.
- void* operator new(size_t size, Zone* zone) {
- return zone->New(static_cast<int>(size));
- }
+ void* operator new(size_t size, Zone* zone) { return zone->New(size); }
// Ideally, the delete operator should be private instead of
// public, but unfortunately the compiler sometimes synthesizes
@@ -160,7 +157,7 @@ class ZoneScope FINAL {
class ZoneAllocationPolicy FINAL {
public:
explicit ZoneAllocationPolicy(Zone* zone) : zone_(zone) { }
- void* New(size_t size) { return zone()->New(static_cast<int>(size)); }
+ void* New(size_t size) { return zone()->New(size); }
static void Delete(void* pointer) {}
Zone* zone() const { return zone_; }
@@ -181,9 +178,7 @@ class ZoneList FINAL : public List<T, ZoneAllocationPolicy> {
ZoneList(int capacity, Zone* zone)
: List<T, ZoneAllocationPolicy>(capacity, ZoneAllocationPolicy(zone)) { }
- void* operator new(size_t size, Zone* zone) {
- return zone->New(static_cast<int>(size));
- }
+ void* operator new(size_t size, Zone* zone) { return zone->New(size); }
// Construct a new ZoneList by copying the elements of the given ZoneList.
ZoneList(const ZoneList<T>& other, Zone* zone)
@@ -239,9 +234,7 @@ class ZoneSplayTree FINAL : public SplayTree<Config, ZoneAllocationPolicy> {
SplayTree<Config, ZoneAllocationPolicy>::ResetRoot();
}
- void* operator new(size_t size, Zone* zone) {
- return zone->New(static_cast<int>(size));
- }
+ void* operator new(size_t size, Zone* zone) { return zone->New(size); }
void operator delete(void* pointer) { UNREACHABLE(); }
void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); }
« no previous file with comments | « src/typing.h ('k') | src/zone.cc » ('j') | src/zone.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698