/* src/vm/descriptor.c - checking and parsing of field / method descriptors
- Copyright (C) 1996-2005, 2006, 2007, 2008
+ Copyright (C) 1996-2011
CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
This file is part of CACAO.
#include "md-abi.h"
-#include "mm/memory.h"
+#include "mm/memory.hpp"
#include "vm/descriptor.hpp"
#include "vm/exceptions.hpp"
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.
- RETURN VALUE:
- true.............the paramdescs were created successfully
- false............an exception has been thrown
-
POSTCONDITION:
md->parms != NULL
*******************************************************************************/
-bool descriptor_params_from_paramtypes(methoddesc *md, s4 mflags)
+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 */
}
#endif
- return true;
-}
-
-
-/* descriptor_pool_get_parsed_descriptors **************************************
-
- Return a pointer to the block of parsed descriptors
-
- IN:
- pool.............the descriptor_pool
-
- OUT:
- *size............if size is non-NULL, this is set to the size of the
- parsed descriptor block (in u1)
-
- RETURN VALUE:
- a pointer to the block of parsed descriptors
-
- NOTE:
- descriptor_pool_alloc_parsed_descriptors must be called (once)
- before this function is used.
-
-*******************************************************************************/
-
-void *
-descriptor_pool_get_parsed_descriptors(descriptor_pool *pool, s4 *size)
-{
- assert(pool);
- assert((!pool->fieldcount && !pool->methodcount) || pool->descriptors);
-
- if (size)
- *size = pool->descriptorsize;
-
- return pool->descriptors;
+ if (has_lock)
+ md->pool_lock->unlock();
}