Skip to content

Commit

Permalink
Generalize attribute_as_atomic to obj attrs too
Browse files Browse the repository at this point in the history
In preparation for adding some atomic store and atomic bind ops for
attributes.
  • Loading branch information
jnthn committed Jun 13, 2018
1 parent 6302ca7 commit 217b687
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/6model/6model.h
Expand Up @@ -388,11 +388,11 @@ struct MVMREPROps_Attribute {
MVMint64 hint);

/* Provided the attribute is a native integer of the architecture's atomic
* size, returns an AO_t * referencing it. This is only valid until the
* next safepoint. If rebless is called on the object, updates may be lost
* although memory safety must not be violated. */
* size or an object pointer, returns an AO_t * referencing it. This is only
* valid until the next safepoint. If rebless is called on the object,
* updates may be lost although memory safety must not be violated. */
AO_t * (*attribute_as_atomic) (MVMThreadContext *tc, MVMSTable *st,
void *data, MVMObject *class_handle, MVMString *name);
void *data, MVMObject *class_handle, MVMString *name, MVMuint16 kind);
};
struct MVMREPROps_Boxing {
/* Used with boxing. Sets an integer value, for representations that
Expand Down
2 changes: 1 addition & 1 deletion src/6model/reprs.c
Expand Up @@ -24,7 +24,7 @@ GCC_DIAG_OFF(return-type)
MVMint64 MVM_REPR_DEFAULT_IS_ATTRIBUTE_INITIALIZED(MVMThreadContext *tc, MVMSTable *st, void *data, MVMObject *class_handle, MVMString *name, MVMint64 hint) {
die_no_attrs(tc, st->REPR->name, MVM_6model_get_stable_debug_name(tc, st));
}
AO_t * MVM_REPR_DEFAULT_ATTRIBUTE_AS_ATOMIC(MVMThreadContext *tc, MVMSTable *st, void *data, MVMObject *class_handle, MVMString *name) {
AO_t * MVM_REPR_DEFAULT_ATTRIBUTE_AS_ATOMIC(MVMThreadContext *tc, MVMSTable *st, void *data, MVMObject *class_handle, MVMString *name, MVMuint16 kind) {
die_no_attrs(tc, st->REPR->name, MVM_6model_get_stable_debug_name(tc, st));
}
GCC_DIAG_ON(return-type)
Expand Down
2 changes: 1 addition & 1 deletion src/6model/reprs.h
Expand Up @@ -174,7 +174,7 @@ void MVM_REPR_DEFAULT_GET_ATTRIBUTE(MVMThreadContext *tc, MVMSTable *st, MVMObje
void MVM_REPR_DEFAULT_BIND_ATTRIBUTE(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data, MVMObject *class_handle, MVMString *name, MVMint64 hint, MVMRegister value, MVMuint16 kind);
MVMint64 MVM_REPR_DEFAULT_IS_ATTRIBUTE_INITIALIZED(MVMThreadContext *tc, MVMSTable *st, void *data, MVMObject *class_handle, MVMString *name, MVMint64 hint);
MVMint64 MVM_REPR_DEFAULT_HINT_FOR(MVMThreadContext *tc, MVMSTable *st, MVMObject *class_handle, MVMString *name);
AO_t * MVM_REPR_DEFAULT_ATTRIBUTE_AS_ATOMIC(MVMThreadContext *tc, MVMSTable *st, void *data, MVMObject *class_handle, MVMString *name);
AO_t * MVM_REPR_DEFAULT_ATTRIBUTE_AS_ATOMIC(MVMThreadContext *tc, MVMSTable *st, void *data, MVMObject *class_handle, MVMString *name, MVMuint16 kind);

/* Default boxing REPR function for a REPR that lacks it. */
void MVM_REPR_DEFAULT_SET_INT(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data, MVMint64 value);
Expand Down
2 changes: 1 addition & 1 deletion src/6model/reprs/NativeRef.c
Expand Up @@ -592,7 +592,7 @@ AO_t * MVM_nativeref_as_atomic_attribute_i(MVMThreadContext *tc, MVMObject *ref_
MVMNativeRef *ref = (MVMNativeRef *)ref_obj;
MVMObject *obj = ref->body.u.attribute.obj;
return REPR(obj)->attr_funcs.attribute_as_atomic(tc, STABLE(obj), OBJECT_BODY(obj),
ref->body.u.attribute.class_handle, ref->body.u.attribute.name);
ref->body.u.attribute.class_handle, ref->body.u.attribute.name, MVM_reg_int64);
}
AO_t * MVM_nativeref_as_atomic_positional_i(MVMThreadContext *tc, MVMObject *ref_obj) {
MVMNativeRef *ref = (MVMNativeRef *)ref_obj;
Expand Down
28 changes: 19 additions & 9 deletions src/6model/reprs/P6opaque.c
Expand Up @@ -431,7 +431,8 @@ static MVMint64 hint_for(MVMThreadContext *tc, MVMSTable *st, MVMObject *class_k
/* Gets an architecture atomic sized native integer attribute as an atomic
* reference. */
static AO_t * attribute_as_atomic(MVMThreadContext *tc, MVMSTable *st, void *data,
MVMObject *class_handle, MVMString *name) {
MVMObject *class_handle, MVMString *name,
MVMuint16 kind) {
MVMP6opaqueREPRData *repr_data = (MVMP6opaqueREPRData *)st->REPR_data;
MVMint64 slot;
data = MVM_p6opaque_real_data(tc, data);
Expand All @@ -440,15 +441,24 @@ static AO_t * attribute_as_atomic(MVMThreadContext *tc, MVMSTable *st, void *dat
"P6opaque: must compose %s before using get_attribute", MVM_6model_get_stable_debug_name(tc, st));
slot = try_get_slot(tc, repr_data, class_handle, name);
if (slot >= 0) {
MVMSTable *attr_st = repr_data->flattened_stables[slot];
if (attr_st) {
const MVMStorageSpec *ss = attr_st->REPR->get_storage_spec(tc, attr_st);
if (ss->inlineable && ss->boxed_primitive == MVM_STORAGE_SPEC_BP_INT &&
ss->bits / 8 == sizeof(AO_t))
return (AO_t *)((char *)data + repr_data->attribute_offsets[slot]);
if (kind == MVM_reg_int64) {
MVMSTable *attr_st = repr_data->flattened_stables[slot];
if (attr_st) {
const MVMStorageSpec *ss = attr_st->REPR->get_storage_spec(tc, attr_st);
if (ss->inlineable && ss->boxed_primitive == MVM_STORAGE_SPEC_BP_INT &&
ss->bits / 8 == sizeof(AO_t))
return (AO_t *)((char *)data + repr_data->attribute_offsets[slot]);
}
MVM_exception_throw_adhoc(tc,
"Can only do an atomic integer operation on an atomicint attribute");
}
else if (kind == MVM_reg_obj) {
return (AO_t *)((char *)data + repr_data->attribute_offsets[slot]);
}
else {
MVM_exception_throw_adhoc(tc,
"Can only perform atomic operations on object or atomicint attributes");
}
MVM_exception_throw_adhoc(tc,
"Can only do an atomic integer operation on an atomicint attribute");
}
else {
no_such_attribute(tc, "get atomic reference to", class_handle, name, st);
Expand Down

0 comments on commit 217b687

Please sign in to comment.