219 enum { DC_LIMIT = 20 };
220 static DelayedConstant delayed_constants[DC_LIMIT];
221 static DelayedConstant* add(BasicType type, value_fn_t value_fn);
222 bool match(BasicType t, value_fn_t cfn) {
223 return type == t && value_fn == cfn;
224 }
225 static void update_all();
226 };
227
228 DelayedConstant DelayedConstant::delayed_constants[DC_LIMIT];
229 // Default C structure initialization rules have the following effect here:
230 // = { { (BasicType)0, (intptr_t)NULL }, ... };
231
232 DelayedConstant* DelayedConstant::add(BasicType type,
233 DelayedConstant::value_fn_t cfn) {
234 for (int i = 0; i < DC_LIMIT; i++) {
235 DelayedConstant* dcon = &delayed_constants[i];
236 if (dcon->match(type, cfn))
237 return dcon;
238 if (dcon->value_fn == NULL) {
239 // (cmpxchg not because this is multi-threaded but because I'm paranoid)
240 if (Atomic::cmpxchg_ptr(CAST_FROM_FN_PTR(void*, cfn), &dcon->value_fn, NULL) == NULL) {
241 dcon->type = type;
242 return dcon;
243 }
244 }
245 }
246 // If this assert is hit (in pre-integration testing!) then re-evaluate
247 // the comment on the definition of DC_LIMIT.
248 guarantee(false, "too many delayed constants");
249 return NULL;
250 }
251
252 void DelayedConstant::update_all() {
253 for (int i = 0; i < DC_LIMIT; i++) {
254 DelayedConstant* dcon = &delayed_constants[i];
255 if (dcon->value_fn != NULL && dcon->value == 0) {
256 typedef int (*int_fn_t)();
257 typedef address (*address_fn_t)();
258 switch (dcon->type) {
259 case T_INT: dcon->value = (intptr_t) ((int_fn_t) dcon->value_fn)(); break;
260 case T_ADDRESS: dcon->value = (intptr_t) ((address_fn_t)dcon->value_fn)(); break;
261 default: break;
262 }
263 }
|
219 enum { DC_LIMIT = 20 };
220 static DelayedConstant delayed_constants[DC_LIMIT];
221 static DelayedConstant* add(BasicType type, value_fn_t value_fn);
222 bool match(BasicType t, value_fn_t cfn) {
223 return type == t && value_fn == cfn;
224 }
225 static void update_all();
226 };
227
228 DelayedConstant DelayedConstant::delayed_constants[DC_LIMIT];
229 // Default C structure initialization rules have the following effect here:
230 // = { { (BasicType)0, (intptr_t)NULL }, ... };
231
232 DelayedConstant* DelayedConstant::add(BasicType type,
233 DelayedConstant::value_fn_t cfn) {
234 for (int i = 0; i < DC_LIMIT; i++) {
235 DelayedConstant* dcon = &delayed_constants[i];
236 if (dcon->match(type, cfn))
237 return dcon;
238 if (dcon->value_fn == NULL) {
239 dcon->value_fn = cfn;
240 dcon->type = type;
241 return dcon;
242 }
243 }
244 // If this assert is hit (in pre-integration testing!) then re-evaluate
245 // the comment on the definition of DC_LIMIT.
246 guarantee(false, "too many delayed constants");
247 return NULL;
248 }
249
250 void DelayedConstant::update_all() {
251 for (int i = 0; i < DC_LIMIT; i++) {
252 DelayedConstant* dcon = &delayed_constants[i];
253 if (dcon->value_fn != NULL && dcon->value == 0) {
254 typedef int (*int_fn_t)();
255 typedef address (*address_fn_t)();
256 switch (dcon->type) {
257 case T_INT: dcon->value = (intptr_t) ((int_fn_t) dcon->value_fn)(); break;
258 case T_ADDRESS: dcon->value = (intptr_t) ((address_fn_t)dcon->value_fn)(); break;
259 default: break;
260 }
261 }
|