本文整理汇总了C++中MVM_calloc函数的典型用法代码示例。如果您正苦于以下问题:C++ MVM_calloc函数的具体用法?C++ MVM_calloc怎么用?C++ MVM_calloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MVM_calloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MVM_tc_create
/* Initializes a new thread context. Note that this doesn't set up a
* thread itself, it just creates the data structure that exists in
* MoarVM per thread. */
MVMThreadContext * MVM_tc_create(MVMThreadContext *parent, MVMInstance *instance) {
MVMThreadContext *tc = MVM_calloc(1, sizeof(MVMThreadContext));
MVMint32 i;
/* Associate with VM instance. */
tc->instance = instance;
/* Set up GC nursery. We only allocate tospace initially, and allocate
* fromspace the first time this thread GCs, provided it ever does. */
tc->nursery_tospace_size = MVM_gc_new_thread_nursery_size(instance);
tc->nursery_tospace = MVM_calloc(1, tc->nursery_tospace_size);
tc->nursery_alloc = tc->nursery_tospace;
tc->nursery_alloc_limit = (char *)tc->nursery_alloc + tc->nursery_tospace_size;
/* Set up temporary root handling. */
tc->num_temproots = 0;
tc->alloc_temproots = MVM_TEMP_ROOT_BASE_ALLOC;
tc->temproots = MVM_malloc(sizeof(MVMCollectable **) * tc->alloc_temproots);
/* Set up intergenerational root handling. */
tc->num_gen2roots = 0;
tc->alloc_gen2roots = 64;
tc->gen2roots = MVM_malloc(sizeof(MVMCollectable *) * tc->alloc_gen2roots);
/* Set up the second generation allocator. */
tc->gen2 = MVM_gc_gen2_create(instance);
/* The fixed size allocator also keeps pre-thread state. */
MVM_fixed_size_create_thread(tc);
/* Allocate an initial call stack region for the thread. */
MVM_callstack_region_init(tc);
/* Initialize random number generator state. */
MVM_proc_seed(tc, (MVM_platform_now() / 10000) * MVM_proc_getpid(tc));
/* Allocate temporary big integers. */
for (i = 0; i < MVM_NUM_TEMP_BIGINTS; i++) {
tc->temp_bigints[i] = MVM_malloc(sizeof(mp_int));
mp_init(tc->temp_bigints[i]);
}
/* Initialize frame sequence numbers */
tc->next_frame_nr = 0;
tc->current_frame_nr = 0;
/* Initialize last_payload, so we can be sure it's never NULL and don't
* need to check. */
tc->last_payload = instance->VMNull;
/* Initialize plugin_guard_args so we never have to do a NULL check */
tc->plugin_guard_args = instance->VMNull;
/* Note that these two assignments above are repeated in
* MVM_6model_bootstrap because VMNull doesn't exist yet when the very
* first tc is created. */
return tc;
}
示例2: MVM_tc_create
/* Initializes a new thread context. Note that this doesn't set up a
* thread itself, it just creates the data structure that exists in
* MoarVM per thread. */
MVMThreadContext * MVM_tc_create(MVMThreadContext *parent, MVMInstance *instance) {
MVMThreadContext *tc = MVM_calloc(1, sizeof(MVMThreadContext));
/* Associate with VM instance. */
tc->instance = instance;
/* Use default loop for main thread; create a new one for others. */
if (instance->main_thread) {
int r;
tc->loop = MVM_calloc(1, sizeof(uv_loop_t));
r = uv_loop_init(tc->loop);
if (r < 0) {
MVM_free(tc->loop);
MVM_free(tc);
MVM_exception_throw_adhoc(parent, "Could not create a new Thread: %s", uv_strerror(r));
}
} else {
tc->loop = uv_default_loop();
}
/* Set up GC nursery. We only allocate tospace initially, and allocate
* fromspace the first time this thread GCs, provided it ever does. */
tc->nursery_tospace = MVM_calloc(1, MVM_NURSERY_SIZE);
tc->nursery_alloc = tc->nursery_tospace;
tc->nursery_alloc_limit = (char *)tc->nursery_alloc + MVM_NURSERY_SIZE;
/* Set up temporary root handling. */
tc->num_temproots = 0;
tc->alloc_temproots = MVM_TEMP_ROOT_BASE_ALLOC;
tc->temproots = MVM_malloc(sizeof(MVMCollectable **) * tc->alloc_temproots);
/* Set up intergenerational root handling. */
tc->num_gen2roots = 0;
tc->alloc_gen2roots = 64;
tc->gen2roots = MVM_malloc(sizeof(MVMCollectable *) * tc->alloc_gen2roots);
/* Set up the second generation allocator. */
tc->gen2 = MVM_gc_gen2_create(instance);
/* Allocate an initial call stack region for the thread. */
MVM_callstack_region_init(tc);
/* Initialize random number generator state. */
MVM_proc_seed(tc, (MVM_platform_now() / 10000) * MVM_proc_getpid(tc));
/* Initialize frame sequence numbers */
tc->next_frame_nr = 0;
tc->current_frame_nr = 0;
/* Initialize last_payload, so we can be sure it's never NULL and don't
* need to check. */
tc->last_payload = instance->VMNull;
return tc;
}
示例3: MVM_string_decodestream_create
/* Creates a new decoding stream. */
MVMDecodeStream * MVM_string_decodestream_create(MVMThreadContext *tc, MVMint32 encoding, MVMint64 abs_byte_pos) {
MVMDecodeStream *ds = MVM_calloc(1, sizeof(MVMDecodeStream));
ds->encoding = encoding;
ds->abs_byte_pos = abs_byte_pos;
MVM_unicode_normalizer_init(tc, &(ds->norm), MVM_NORMALIZE_NFG);
return ds;
}
示例4: MVM_args_copy_callsite
/* Make a copy of the callsite. */
MVMCallsite * MVM_args_copy_callsite(MVMThreadContext *tc, MVMArgProcContext *ctx) {
MVMCallsite *res = MVM_calloc(1, sizeof(MVMCallsite));
MVMCallsiteEntry *flags = NULL;
MVMCallsiteEntry *src_flags;
MVMint32 fsize;
if (ctx->arg_flags) {
fsize = ctx->flag_count;
src_flags = ctx->arg_flags;
}
else {
fsize = ctx->callsite->flag_count;
src_flags = ctx->callsite->arg_flags;
}
if (fsize) {
flags = MVM_malloc(fsize * sizeof(MVMCallsiteEntry));
memcpy(flags, src_flags, fsize * sizeof(MVMCallsiteEntry));
}
res->flag_count = fsize;
res->arg_flags = flags;
res->arg_count = ctx->arg_count;
res->num_pos = ctx->num_pos;
return res;
}
示例5: MVM_region_alloc
void * MVM_region_alloc(MVMThreadContext *tc, MVMRegionAlloc *al, size_t bytes) {
char *result = NULL;
#if !defined(MVM_CAN_UNALIGNED_INT64) || !defined(MVM_CAN_UNALIGNED_NUM64)
/* Round up size to next multiple of 8, to ensure alignment. */
bytes = (bytes + 7) & ~7;
#endif
if (al->block != NULL && (al->block->alloc + bytes) < al->block->limit) {
result = al->block->alloc;
al->block->alloc += bytes;
} else {
/* No block, or block was full. Add another. */
MVMRegionBlock *block = MVM_malloc(sizeof(MVMRegionBlock));
size_t buffer_size = al->block == NULL
? MVM_REGIONALLOC_FIRST_MEMBLOCK_SIZE
: MVM_REGIONALLOC_MEMBLOCK_SIZE;
if (buffer_size < bytes)
buffer_size = bytes;
block->buffer = MVM_calloc(1, buffer_size);
block->alloc = block->buffer;
block->limit = block->buffer + buffer_size;
block->prev = al->block;
al->block = block;
/* Now allocate out of it. */
result = block->alloc;
block->alloc += bytes;
}
return result;
}
示例6: MVM_file_open_fh
/* Opens a file, returning a synchronous file handle. */
MVMObject * MVM_file_open_fh(MVMThreadContext *tc, MVMString *filename, MVMString *mode) {
char * const fname = MVM_string_utf8_encode_C_string(tc, filename);
char * const fmode = MVM_string_utf8_encode_C_string(tc, mode);
MVMOSHandle * const result = (MVMOSHandle *)MVM_repr_alloc_init(tc, tc->instance->boot_types.BOOTIO);
MVMIOFileData * const data = MVM_calloc(1, sizeof(MVMIOFileData));
uv_fs_t req;
uv_file fd;
/* Resolve mode description to flags. */
int flag;
if (!resolve_open_mode(&flag, fmode)) {
char *waste[] = { fmode, NULL };
MVM_free(fname);
MVM_exception_throw_adhoc_free(tc, waste, "Invalid open mode: %s", fmode);
}
MVM_free(fmode);
/* Try to open the file. */
if ((fd = uv_fs_open(tc->loop, &req, (const char *)fname, flag, DEFAULT_MODE, NULL)) < 0) {
char *waste[] = { fname, NULL };
MVM_exception_throw_adhoc_free(tc, waste, "Failed to open file %s: %s", fname, uv_strerror(req.result));
}
/* Set up handle. */
data->fd = fd;
data->filename = fname;
data->encoding = MVM_encoding_type_utf8;
result->body.ops = &op_table;
result->body.data = data;
return (MVMObject *)result;
}
示例7: MVM_profile_log_enter
/* Log that we're entering a new frame. */
void MVM_profile_log_enter(MVMThreadContext *tc, MVMStaticFrame *sf, MVMuint64 mode) {
MVMProfileThreadData *ptd = get_thread_data(tc);
/* Try to locate the entry node, if it's in the call graph already. */
MVMProfileCallNode *pcn = NULL;
MVMuint32 i;
if (ptd->current_call)
for (i = 0; i < ptd->current_call->num_succ; i++)
if (ptd->current_call->succ[i]->sf == sf)
pcn = ptd->current_call->succ[i];
/* If we didn't find a call graph node, then create one and add it to the
* graph. */
if (!pcn) {
pcn = MVM_calloc(1, sizeof(MVMProfileCallNode));
pcn->sf = sf;
if (ptd->current_call) {
MVMProfileCallNode *pred = ptd->current_call;
pcn->pred = pred;
if (pred->num_succ == pred->alloc_succ) {
pred->alloc_succ += 8;
pred->succ = MVM_realloc(pred->succ,
pred->alloc_succ * sizeof(MVMProfileCallNode *));
}
pred->succ[pred->num_succ] = pcn;
pred->num_succ++;
}
else {
if (!ptd->call_graph)
ptd->call_graph = pcn;
}
}
/* Increment entry counts. */
pcn->total_entries++;
switch (mode) {
case MVM_PROFILE_ENTER_SPESH:
pcn->specialized_entries++;
break;
case MVM_PROFILE_ENTER_SPESH_INLINE:
pcn->specialized_entries++;
pcn->inlined_entries++;
break;
case MVM_PROFILE_ENTER_JIT:
pcn->jit_entries++;
break;
case MVM_PROFILE_ENTER_JIT_INLINE:
pcn->jit_entries++;
pcn->inlined_entries++;
break;
}
pcn->entry_mode = mode;
/* Log entry time; clear skip time. */
pcn->cur_entry_time = uv_hrtime();
pcn->cur_skip_time = 0;
/* The current call graph node becomes this one. */
ptd->current_call = pcn;
}
示例8: MVM_io_socket_create
MVMObject * MVM_io_socket_create(MVMThreadContext *tc, MVMint64 listen) {
MVMOSHandle * const result = (MVMOSHandle *)MVM_repr_alloc_init(tc, tc->instance->boot_types.BOOTIO);
MVMIOSyncSocketData * const data = MVM_calloc(1, sizeof(MVMIOSyncSocketData));
result->body.ops = &op_table;
result->body.data = data;
return (MVMObject *)result;
}
示例9: socket_accept
static MVMObject * socket_accept(MVMThreadContext *tc, MVMOSHandle *h) {
MVMIOSyncSocketData *data = (MVMIOSyncSocketData *)h->body.data;
Socket s;
unsigned int interval_id = MVM_telemetry_interval_start(tc, "syncsocket accept");
do {
MVM_gc_mark_thread_blocked(tc);
s = accept(data->handle, NULL, NULL);
MVM_gc_mark_thread_unblocked(tc);
} while(s == -1 && errno == EINTR);
if (MVM_IS_SOCKET_ERROR(s)) {
MVM_telemetry_interval_stop(tc, interval_id, "syncsocket accept failed");
throw_error(tc, s, "accept socket connection");
}
else {
MVMOSHandle * const result = (MVMOSHandle *)MVM_repr_alloc_init(tc,
tc->instance->boot_types.BOOTIO);
MVMIOSyncSocketData * const data = MVM_calloc(1, sizeof(MVMIOSyncSocketData));
data->handle = s;
result->body.ops = &op_table;
result->body.data = data;
MVM_telemetry_interval_stop(tc, interval_id, "syncsocket accept succeeded");
return (MVMObject *)result;
}
}
示例10: MVM_spesh_alloc
/* Allocate a piece of memory from the spesh graph's buffer. Deallocated when
* the spesh graph is. */
void * MVM_spesh_alloc(MVMThreadContext *tc, MVMSpeshGraph *g, size_t bytes) {
char *result = NULL;
#if !defined(MVM_CAN_UNALIGNED_INT64) || !defined(MVM_CAN_UNALIGNED_NUM64)
/* Round up size to next multiple of 8, to ensure alignment. */
bytes = (bytes + 7) & ~7;
#endif
if (g->mem_block) {
MVMSpeshMemBlock *block = g->mem_block;
if (block->alloc + bytes < block->limit) {
result = block->alloc;
block->alloc += bytes;
}
}
if (!result) {
/* No block, or block was full. Add another. */
MVMSpeshMemBlock *block = MVM_malloc(sizeof(MVMSpeshMemBlock));
block->buffer = MVM_calloc(MVM_SPESH_MEMBLOCK_SIZE, 1);
block->alloc = block->buffer;
block->limit = block->buffer + MVM_SPESH_MEMBLOCK_SIZE;
block->prev = g->mem_block;
g->mem_block = block;
/* Now allocate out of it. */
if (bytes > MVM_SPESH_MEMBLOCK_SIZE) {
MVM_spesh_graph_destroy(tc, g);
MVM_exception_throw_adhoc(tc, "MVM_spesh_alloc: requested oversized block");
}
result = block->alloc;
block->alloc += bytes;
}
return result;
}
示例11: get_thread_data
/* Gets the current thread's profiling data structure, creating it if needed. */
static MVMProfileThreadData * get_thread_data(MVMThreadContext *tc) {
if (!tc->prof_data) {
tc->prof_data = MVM_calloc(1, sizeof(MVMProfileThreadData));
tc->prof_data->start_time = uv_hrtime();
}
return tc->prof_data;
}
示例12: MVM_bytecode_finish_frame
/* Finishes up reading and exploding of a frame. */
void MVM_bytecode_finish_frame(MVMThreadContext *tc, MVMCompUnit *cu,
MVMStaticFrame *sf, MVMint32 dump_only) {
MVMuint32 j;
MVMuint8 *pos;
MVMuint16 slvs;
/* Ensure we've not already done this. */
if (sf->body.fully_deserialized)
return;
/* Acquire the update mutex on the CompUnit. */
MVM_reentrantmutex_lock(tc, (MVMReentrantMutex *)cu->body.update_mutex);
/* Ensure no other thread has done this for us in the mean time. */
if (sf->body.fully_deserialized) {
MVM_reentrantmutex_unlock(tc, (MVMReentrantMutex *)cu->body.update_mutex);
return;
}
/* Locate start of frame body. */
pos = sf->body.frame_data_pos;
/* Get the number of static lex values we'll need to apply. */
slvs = read_int16(pos, 40);
/* Skip past header. */
pos += FRAME_HEADER_SIZE;
/* Read the local types. */
if (sf->body.num_locals) {
sf->body.local_types = MVM_malloc(sizeof(MVMuint16) * sf->body.num_locals);
for (j = 0; j < sf->body.num_locals; j++)
sf->body.local_types[j] = read_int16(pos, 2 * j);
pos += 2 * sf->body.num_locals;
}
/* Read the lexical types. */
if (sf->body.num_lexicals) {
/* Allocate names hash and types list. */
sf->body.lexical_types = MVM_malloc(sizeof(MVMuint16) * sf->body.num_lexicals);
/* Read in data. */
if (sf->body.num_lexicals) {
sf->body.lexical_names_list = MVM_malloc(sizeof(MVMLexicalRegistry *) * sf->body.num_lexicals);
}
for (j = 0; j < sf->body.num_lexicals; j++) {
MVMString *name = get_heap_string(tc, cu, NULL, pos, 6 * j + 2);
MVMLexicalRegistry *entry = MVM_calloc(1, sizeof(MVMLexicalRegistry));
MVM_ASSIGN_REF(tc, &(sf->common.header), entry->key, name);
sf->body.lexical_names_list[j] = entry;
entry->value = j;
sf->body.lexical_types[j] = read_int16(pos, 6 * j);
MVM_string_flatten(tc, name);
MVM_HASH_BIND(tc, sf->body.lexical_names, name, entry)
}
pos += 6 * sf->body.num_lexicals;
}
示例13: MVM_fixed_size_create
/* Creates the allocator data structure with bins. */
MVMFixedSizeAlloc * MVM_fixed_size_create(MVMThreadContext *tc) {
int init_stat;
MVMFixedSizeAlloc *al = MVM_malloc(sizeof(MVMFixedSizeAlloc));
al->size_classes = MVM_calloc(MVM_FSA_BINS, sizeof(MVMFixedSizeAllocSizeClass));
if ((init_stat = uv_mutex_init(&(al->complex_alloc_mutex))) < 0)
MVM_exception_throw_adhoc(tc, "Failed to initialize mutex: %s",
uv_strerror(init_stat));
return al;
}
示例14: MVM_file_handle_from_fd
/* Opens a file, returning a synchronous file handle. */
MVMObject * MVM_file_handle_from_fd(MVMThreadContext *tc, uv_file fd) {
MVMOSHandle * const result = (MVMOSHandle *)MVM_repr_alloc_init(tc, tc->instance->boot_types.BOOTIO);
MVMIOFileData * const data = MVM_calloc(1, sizeof(MVMIOFileData));
data->fd = fd;
data->encoding = MVM_encoding_type_utf8;
result->body.ops = &op_table;
result->body.data = data;
return (MVMObject *)result;
}
示例15: MVM_io_syncstream_from_uvstream
/* Wraps a libuv stream (likely, libuv pipe or TTY) up in a sync stream. */
MVMObject * MVM_io_syncstream_from_uvstream(MVMThreadContext *tc, uv_stream_t *handle) {
MVMOSHandle * const result = (MVMOSHandle *)MVM_repr_alloc_init(tc, tc->instance->boot_types.BOOTIO);
MVMIOSyncStreamData * const data = MVM_calloc(1, sizeof(MVMIOSyncStreamData));
data->handle = handle;
data->encoding = MVM_encoding_type_utf8;
data->sep = '\n';
result->body.ops = &op_table;
result->body.data = data;
return (MVMObject *)result;
}