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

Unified Diff: src/lithium.h

Issue 9455088: Remove static initializers in v8. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Lint. Created 8 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
Index: src/lithium.h
diff --git a/src/lithium.h b/src/lithium.h
index 4987b5a4cd2dc12b9c6f3a4e4c8f95e782314cf1..d031e8781354fc83ef4588b394c41cedd19df317 100644
--- a/src/lithium.h
+++ b/src/lithium.h
@@ -30,6 +30,7 @@
#include "allocation.h"
#include "hydrogen.h"
+#include "once.h"
#include "safepoint-table.h"
namespace v8 {
@@ -76,6 +77,15 @@ class LOperand: public ZoneObject {
LOperand(Kind kind, int index) { ConvertTo(kind, index); }
unsigned value_;
+
+ // Function used by subclasses to populate their cache.
+ template <typename T, int Size, LOperand::Kind _Kind>
+ static void InitCache(T** cache) {
+ *cache = new T[Size];
+ for (int i = 0; i < Size; i++) {
+ (*cache)[i].ConvertTo(_Kind, i);
+ }
+ }
};
@@ -246,11 +256,11 @@ class LMoveOperands BASE_EMBEDDED {
LOperand* destination_;
};
fschneider 2012/02/28 16:54:48 Accidental edit?
-
class LConstantOperand: public LOperand {
public:
static LConstantOperand* Create(int index) {
ASSERT(index >= 0);
+ SetUpCache();
fschneider 2012/02/28 16:54:48 Creation of LOperand is a really frequent operatio
Philippe 2012/02/29 10:24:45 Done.
if (index < kNumCachedOperands) return &cache[index];
return new LConstantOperand(index);
}
@@ -264,10 +274,15 @@ class LConstantOperand: public LOperand {
private:
static const int kNumCachedOperands = 128;
- static LConstantOperand cache[];
+ static LConstantOperand* cache;
+ static OnceType init_cache_once_;
LConstantOperand() : LOperand() { }
explicit LConstantOperand(int index) : LOperand(CONSTANT_OPERAND, index) { }
+
+ friend void LOperand::InitCache<
+ LConstantOperand, kNumCachedOperands, CONSTANT_OPERAND>(
+ LConstantOperand** cache);
};
@@ -286,6 +301,7 @@ class LStackSlot: public LOperand {
public:
static LStackSlot* Create(int index) {
ASSERT(index >= 0);
+ SetUpCache();
if (index < kNumCachedOperands) return &cache[index];
return new LStackSlot(index);
}
@@ -299,10 +315,14 @@ class LStackSlot: public LOperand {
private:
static const int kNumCachedOperands = 128;
- static LStackSlot cache[];
+ static LStackSlot* cache;
+ static OnceType init_cache_once_;
LStackSlot() : LOperand() { }
explicit LStackSlot(int index) : LOperand(STACK_SLOT, index) { }
+
+ friend void LOperand::InitCache<LStackSlot, kNumCachedOperands, STACK_SLOT>(
+ LStackSlot** cache);
};
@@ -310,6 +330,7 @@ class LDoubleStackSlot: public LOperand {
public:
static LDoubleStackSlot* Create(int index) {
ASSERT(index >= 0);
+ SetUpCache();
if (index < kNumCachedOperands) return &cache[index];
return new LDoubleStackSlot(index);
}
@@ -323,10 +344,15 @@ class LDoubleStackSlot: public LOperand {
private:
static const int kNumCachedOperands = 128;
- static LDoubleStackSlot cache[];
+ static LDoubleStackSlot* cache;
+ static OnceType init_cache_once_;
LDoubleStackSlot() : LOperand() { }
explicit LDoubleStackSlot(int index) : LOperand(DOUBLE_STACK_SLOT, index) { }
+
+ friend void LOperand::InitCache<
+ LDoubleStackSlot, kNumCachedOperands, DOUBLE_STACK_SLOT>(
+ LDoubleStackSlot** cache);
};
@@ -334,6 +360,7 @@ class LRegister: public LOperand {
public:
static LRegister* Create(int index) {
ASSERT(index >= 0);
+ SetUpCache();
if (index < kNumCachedOperands) return &cache[index];
return new LRegister(index);
}
@@ -347,10 +374,14 @@ class LRegister: public LOperand {
private:
static const int kNumCachedOperands = 16;
- static LRegister cache[];
+ static LRegister* cache;
+ static OnceType init_cache_once_;
LRegister() : LOperand() { }
explicit LRegister(int index) : LOperand(REGISTER, index) { }
+
+ friend void LOperand::InitCache<LRegister, kNumCachedOperands, REGISTER>(
+ LRegister** cache);
};
@@ -358,6 +389,7 @@ class LDoubleRegister: public LOperand {
public:
static LDoubleRegister* Create(int index) {
ASSERT(index >= 0);
+ SetUpCache();
if (index < kNumCachedOperands) return &cache[index];
return new LDoubleRegister(index);
}
@@ -371,10 +403,15 @@ class LDoubleRegister: public LOperand {
private:
static const int kNumCachedOperands = 16;
- static LDoubleRegister cache[];
+ static LDoubleRegister* cache;
+ static OnceType init_cache_once_;
LDoubleRegister() : LOperand() { }
explicit LDoubleRegister(int index) : LOperand(DOUBLE_REGISTER, index) { }
+
+ friend void LOperand::InitCache<
+ LDoubleRegister, kNumCachedOperands, DOUBLE_REGISTER>(
+ LDoubleRegister** cache);
};

Powered by Google App Engine
This is Rietveld 408576698