pool->descriptorsize = size;
if (size) {
+ size += sizeof(Mutex); /* prepend Mutex */
pool->descriptors = MNEW(u1, size);
+ /* call Mutex constructor */
+ new (reinterpret_cast<Mutex*>(pool->descriptors)) Mutex;
+ pool->descriptors += sizeof(Mutex);
pool->descriptors_next = pool->descriptors;
}
assert(d);
md = (methoddesc *) pool->descriptors_next;
+ md->pool_lock = reinterpret_cast<Mutex*>(pool->descriptors - sizeof(Mutex));
pool->descriptors_next += sizeof(methoddesc) - sizeof(typedesc);
utf_ptr = desc->text + 1; /* skip '(' */
md_param_alloc(md);
}
#endif
+
+ /* params already initialized; no need to lock */
+ md->pool_lock = NULL;
}
else {
/* params will be allocated later by
/* descriptor_params_from_paramtypes *******************************************
- Create the paramdescs for a method descriptor. This function is called
- when we know whether the method is static or not. This function may only
- be called once for each methoddesc, and only if md->params == NULL.
+ Create the paramdescs for a method descriptor. This function is
+ called when we know whether the method is static or not. This
+ function does nothing if md->params != NULL (checked atomically).
IN:
md...............the parsed method descriptor
- md->params MUST be NULL.
mflags...........the ACC_* access flags of the method. Only the
ACC_STATIC bit is checked.
The value ACC_UNDEF is NOT allowed.
void descriptor_params_from_paramtypes(methoddesc *md, s4 mflags)
{
- typedesc *td;
+ bool has_lock = md->pool_lock;
assert(md);
+ if (md->pool_lock)
+ md->pool_lock->lock();
+ if (md->params) {
+ if (has_lock)
+ md->pool_lock->unlock();
+ return;
+ }
assert(md->params == NULL);
assert(mflags != ACC_UNDEF);
- td = md->paramtypes;
+ typedesc *td = md->paramtypes;
/* check for `this' pointer */
md_param_alloc(md);
}
#endif
+
+ if (has_lock)
+ md->pool_lock->unlock();
}