Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c56ace

Browse files
committed
JIT-inline structure allocation
For simple structure types (no guards, no auto fields, no procedure property). Inlined allocation makes structure allocation a little faster; more significantly, it make structure allocation future-safe.
1 parent 79ada3b commit 2c56ace

12 files changed

Lines changed: 659 additions & 253 deletions

File tree

src/racket/include/scheme.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ typedef struct Scheme_Offset_Cptr
679679
/* Values with SCHEME_PRIM_OTHER_TYPE_MASK */
680680
#define SCHEME_PRIM_STRUCT_TYPE_INDEXLESS_GETTER (32 | 256)
681681
#define SCHEME_PRIM_STRUCT_TYPE_CONSTR 128
682+
#define SCHEME_PRIM_STRUCT_TYPE_SIMPLE_CONSTR (32 | 64 | 128)
682683
#define SCHEME_PRIM_STRUCT_TYPE_INDEXLESS_SETTER 256
683684
#define SCHEME_PRIM_STRUCT_TYPE_INDEXED_SETTER (128 | 256)
684685
#define SCHEME_PRIM_STRUCT_TYPE_BROKEN_INDEXED_SETTER (32 | 128)

src/racket/src/future.c

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3096,6 +3096,36 @@ void scheme_rtcall_allocate_values(int count, Scheme_Thread *t)
30963096
future->arg_s0 = NULL;
30973097
}
30983098

3099+
Scheme_Structure *scheme_rtcall_allocate_structure(int count, Scheme_Struct_Type *t)
3100+
XFORM_SKIP_PROC
3101+
/* Called in future thread */
3102+
{
3103+
Scheme_Future_Thread_State *fts = scheme_future_thread_state;
3104+
future_t *future = fts->thread->current_ft;
3105+
Scheme_Object *retval;
3106+
3107+
future->prim_protocol = SIG_ALLOC_STRUCT;
3108+
3109+
future->arg_i0 = count;
3110+
future->arg_s0 = (Scheme_Object *)t;
3111+
3112+
future->time_of_request = get_future_timestamp();
3113+
future->source_of_request = "[allocate_structure]";
3114+
future->source_type = FSRC_OTHER;
3115+
3116+
future_do_runtimecall(fts, NULL, 1, 0, 0);
3117+
3118+
/* Fetch the future again, in case moved by a GC */
3119+
future = fts->thread->current_ft;
3120+
3121+
future->arg_s0 = NULL;
3122+
3123+
retval = future->retval_s;
3124+
future->retval_s = NULL;
3125+
3126+
return (Scheme_Structure *)retval;
3127+
}
3128+
30993129
Scheme_Object *scheme_rtcall_tail_apply(Scheme_Object *rator, int argc, Scheme_Object **argv)
31003130
XFORM_SKIP_PROC
31013131
/* Called in future thread */
@@ -3459,7 +3489,7 @@ static void do_invoke_rtcall(Scheme_Future_State *fs, future_t *future)
34593489
}
34603490
case SIG_FUTURE:
34613491
{
3462-
Scheme_Object *s = future->arg_s1;
3492+
GC_CAN_IGNORE Scheme_Object *s = future->arg_s1;
34633493
future->arg_s1 = NULL;
34643494
s = make_future(s, 1, future);
34653495
future->retval_s = s;
@@ -3473,6 +3503,19 @@ static void do_invoke_rtcall(Scheme_Future_State *fs, future_t *future)
34733503

34743504
scheme_jit_allocate_values(future->arg_i0, (Scheme_Thread *)arg_s0);
34753505

3506+
break;
3507+
}
3508+
case SIG_ALLOC_STRUCT:
3509+
{
3510+
GC_CAN_IGNORE Scheme_Object *arg_s0 = future->arg_s0;
3511+
GC_CAN_IGNORE Scheme_Structure *res;
3512+
3513+
future->arg_s0 = NULL;
3514+
3515+
res = scheme_jit_allocate_structure(future->arg_i0, (Scheme_Struct_Type *)arg_s0);
3516+
3517+
future->retval_s = (Scheme_Object *)res;
3518+
34763519
break;
34773520
}
34783521
case SIG_TAIL_APPLY:

src/racket/src/future.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,12 @@ typedef struct fsemaphore_t {
240240
#define SIG_ALLOC 2
241241
#define SIG_ALLOC_MARK_SEGMENT 3
242242
#define SIG_ALLOC_VALUES 4
243-
#define SIG_MAKE_FSEMAPHORE 5
244-
#define SIG_FUTURE 6
245-
#define SIG_WRONG_TYPE_EXN 7
246-
#define SIG_TAIL_APPLY 8
247-
#define SIG_APPLY_AFRESH 9
243+
#define SIG_ALLOC_STRUCT 5
244+
#define SIG_MAKE_FSEMAPHORE 6
245+
#define SIG_FUTURE 7
246+
#define SIG_WRONG_TYPE_EXN 8
247+
#define SIG_TAIL_APPLY 9
248+
#define SIG_APPLY_AFRESH 10
248249

249250
# include "jit_ts_protos.h"
250251

@@ -254,6 +255,7 @@ extern Scheme_Object **scheme_rtcall_on_demand(Scheme_Object **argv);
254255
extern uintptr_t scheme_rtcall_alloc(void);
255256
extern void scheme_rtcall_new_mark_segment(Scheme_Thread *p);
256257
extern void scheme_rtcall_allocate_values(int count, Scheme_Thread *t);
258+
extern Scheme_Structure *scheme_rtcall_allocate_structure(int argc, Scheme_Struct_Type *stype);
257259
extern Scheme_Object *scheme_rtcall_make_fsemaphore(Scheme_Object *ready);
258260
extern Scheme_Object *scheme_rtcall_make_future(Scheme_Object *proc);
259261
extern Scheme_Object *scheme_rtcall_tail_apply(Scheme_Object *rator, int argc, Scheme_Object **argv);

src/racket/src/gen-jit-ts.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
})
154154
(newline))
155155

156-
(define proto-counter 10)
156+
(define proto-counter 11)
157157

158158
(define (gen-protos t)
159159
(define-values (arg-types result-type) (parse-type t))

src/racket/src/jit.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ struct scheme_jit_common_record {
258258
void *struct_prop_get_defl_code, *struct_prop_get_defl_tail_code, *struct_prop_get_defl_multi_code;
259259
void *struct_prop_pred_code, *struct_prop_pred_tail_code, *struct_prop_pred_multi_code;
260260
void *struct_proc_extract_code;
261+
void *struct_constr_unary_code, *struct_constr_unary_tail_code, *struct_constr_unary_multi_code;
262+
void *struct_constr_binary_code, *struct_constr_binary_tail_code, *struct_constr_binary_multi_code;
263+
void *struct_constr_nary_code, *struct_constr_nary_tail_code, *struct_constr_nary_multi_code;
261264
void *bad_app_vals_target;
262265
void *app_values_slow_code, *app_values_multi_slow_code, *app_values_tail_slow_code;
263266
void *values_code;
@@ -1180,6 +1183,9 @@ int scheme_generate_inlined_nary(mz_jit_state *jitter, Scheme_App_Rec *app, int
11801183
int scheme_generate_inlined_test(mz_jit_state *jitter, Scheme_Object *obj, int branch_short,
11811184
Branch_Info *for_branch, int need_sync);
11821185
int scheme_generate_cons_alloc(mz_jit_state *jitter, int rev, int inline_retry);
1186+
int scheme_generate_struct_alloc(mz_jit_state *jitter, int num_args,
1187+
int inline_slow, int pop_and_jump,
1188+
int is_tail, int multi_ok);
11831189

11841190
/**********************************************************************/
11851191
/* jitalloc */
@@ -1232,6 +1238,8 @@ int scheme_generate_tail_call(mz_jit_state *jitter, int num_rands, int direct_na
12321238
int scheme_generate_non_tail_call(mz_jit_state *jitter, int num_rands, int direct_native, int need_set_rs,
12331239
int multi_ok, int nontail_self, int pop_and_jump, int is_inlined, int unboxed_args);
12341240
int scheme_generate_finish_tail_call(mz_jit_state *jitter, int direct_native);
1241+
int scheme_generate_finish_apply(mz_jit_state *jitter);
1242+
int scheme_generate_finish_multi_apply(mz_jit_state *jitter);
12351243
int scheme_generate_finish_tail_apply(mz_jit_state *jitter);
12361244
void scheme_jit_register_sub_func(mz_jit_state *jitter, void *code, Scheme_Object *protocol);
12371245
void scheme_jit_register_helper_func(mz_jit_state *jitter, void *code);
@@ -1281,6 +1289,7 @@ Scheme_Object **scheme_on_demand(Scheme_Object **argv);
12811289
Scheme_Object **scheme_on_demand_with_args(Scheme_Object **in_argv, Scheme_Object **argv, int argv_delta);
12821290

12831291
void scheme_jit_allocate_values(int count, Scheme_Thread *p);
1292+
Scheme_Structure *scheme_jit_allocate_structure(int argc, Scheme_Struct_Type *stype);
12841293

12851294
void scheme_prepare_branch_jump(mz_jit_state *jitter, Branch_Info *for_branch);
12861295
void scheme_branch_for_true(mz_jit_state *jitter, Branch_Info *for_branch);

0 commit comments

Comments
 (0)