ruby-changes:55326
From: k0kubun <ko1@a...>
Date: Sun, 14 Apr 2019 14:26:50 +0900 (JST)
Subject: [ruby-changes:55326] k0kubun:r67533 (trunk): Unify comment styles across MJIT sources
k0kubun 2019-04-14 14:26:46 +0900 (Sun, 14 Apr 2019) New Revision: 67533 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67533 Log: Unify comment styles across MJIT sources I'm writing `//` comments in newer MJIT code after C99 enablement (because I write 1-line comments more often than multi-line comments and `//` requires fewer chars on 1-line) and then they are mixed with `/* */` now. For consistency and to avoid the conversion in future changes, let me finish the rewrite in MJIT-related code. Modified files: trunk/mjit.c trunk/mjit.h trunk/mjit_compile.c trunk/mjit_worker.c trunk/tool/ruby_vm/views/_mjit_compile_ivar.erb Index: mjit_compile.c =================================================================== --- mjit_compile.c (revision 67532) +++ mjit_compile.c (revision 67533) @@ -6,9 +6,9 @@ https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L6 **********************************************************************/ -/* NOTE: All functions in this file are executed on MJIT worker. So don't - call Ruby methods (C functions that may call rb_funcall) or trigger - GC (using ZALLOC, xmalloc, xfree, etc.) in this file. */ +// NOTE: All functions in this file are executed on MJIT worker. So don't +// call Ruby methods (C functions that may call rb_funcall) or trigger +// GC (using ZALLOC, xmalloc, xfree, etc.) in this file. #include "internal.h" @@ -21,13 +21,13 @@ https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L21 #include "insns_info.inc" #include "vm_insnhelper.h" -/* Macros to check if a position is already compiled using compile_status.stack_size_for_pos */ +// Macros to check if a position is already compiled using compile_status.stack_size_for_pos #define NOT_COMPILED_STACK_SIZE -1 #define ALREADY_COMPILED_P(status, pos) (status->stack_size_for_pos[pos] != NOT_COMPILED_STACK_SIZE) -/* Storage to keep compiler's status. This should have information - which is global during one `mjit_compile` call. Ones conditional - in each branch should be stored in `compile_branch`. */ +// Storage to keep compiler's status. This should have information +// which is global during one `mjit_compile` call. Ones conditional +// in each branch should be stored in `compile_branch`. struct compile_status { bool success; // has true if compilation has had no issue int *stack_size_for_pos; // stack_size_for_pos[pos] has stack size for the position (otherwise -1) @@ -41,9 +41,9 @@ struct compile_status { https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L41 struct rb_mjit_compile_info *compile_info; }; -/* Storage to keep data which is consistent in each conditional branch. - This is created and used for one `compile_insns` call and its values - should be copied for extra `compile_insns` call. */ +// Storage to keep data which is consistent in each conditional branch. +// This is created and used for one `compile_insns` call and its values +// should be copied for extra `compile_insns` call. struct compile_branch { unsigned int stack_size; // this simulates sp (stack pointer) of YARV bool finish_p; // if true, compilation in this branch should stop and let another branch to be compiled @@ -92,7 +92,7 @@ compile_case_dispatch_each(VALUE key, VA https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L92 return ST_CONTINUE; } -/* Calling rb_id2str in MJIT worker causes random SEGV. So this is disabled by default. */ +// Calling rb_id2str in MJIT worker causes random SEGV. So this is disabled by default. static void comment_id(FILE *f, ID id) { @@ -120,12 +120,12 @@ comment_id(FILE *f, ID id) https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L120 static void compile_insns(FILE *f, const struct rb_iseq_constant_body *body, unsigned int stack_size, unsigned int pos, struct compile_status *status); -/* Main function of JIT compilation, vm_exec_core counterpart for JIT. Compile one insn to `f`, may modify - b->stack_size and return next position. - - When you add a new instruction to insns.def, it would be nice to have JIT compilation support here but - it's optional. This JIT compiler just ignores ISeq which includes unknown instruction, and ISeq which - does not have it can be compiled as usual. */ +// Main function of JIT compilation, vm_exec_core counterpart for JIT. Compile one insn to `f`, may modify +// b->stack_size and return next position. +// +// When you add a new instruction to insns.def, it would be nice to have JIT compilation support here but +// it's optional. This JIT compiler just ignores ISeq which includes unknown instruction, and ISeq which +// does not have it can be compiled as usual. static unsigned int compile_insn(FILE *f, const struct rb_iseq_constant_body *body, const int insn, const VALUE *operands, const unsigned int pos, struct compile_status *status, struct compile_branch *b) @@ -136,12 +136,12 @@ compile_insn(FILE *f, const struct rb_is https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L136 #include "mjit_compile.inc" /*****************/ - /* If next_pos is already compiled and this branch is not finished yet, - next instruction won't be compiled in C code next and will need `goto`. */ + // If next_pos is already compiled and this branch is not finished yet, + // next instruction won't be compiled in C code next and will need `goto`. if (!b->finish_p && next_pos < body->iseq_size && ALREADY_COMPILED_P(status, next_pos)) { fprintf(f, "goto label_%d;\n", next_pos); - /* Verify stack size assumption is the same among multiple branches */ + // Verify stack size assumption is the same among multiple branches if ((unsigned int)status->stack_size_for_pos[next_pos] != b->stack_size) { if (mjit_opts.warnings || mjit_opts.verbose) fprintf(stderr, "MJIT warning: JIT stack assumption is not the same between branches (%d != %u)\n", @@ -153,8 +153,8 @@ compile_insn(FILE *f, const struct rb_is https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L153 return next_pos; } -/* Compile one conditional branch. If it has branchXXX insn, this should be - called multiple times for each branch. */ +// Compile one conditional branch. If it has branchXXX insn, this should be +// called multiple times for each branch. static void compile_insns(FILE *f, const struct rb_iseq_constant_body *body, unsigned int stack_size, unsigned int pos, struct compile_status *status) @@ -185,7 +185,7 @@ compile_insns(FILE *f, const struct rb_i https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L185 } } -/* Print the block to cancel JIT execution. */ +// Print the block to cancel JIT execution. static void compile_cancel_handler(FILE *f, const struct rb_iseq_constant_body *body, struct compile_status *status) { @@ -222,7 +222,7 @@ mjit_compile(FILE *f, const rb_iseq_t *i https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L222 && !mjit_copy_cache_from_main_thread(iseq, status.cc_entries, status.is_entries)) return false; - /* For performance, we verify stack size only on compilation time (mjit_compile.inc.erb) without --jit-debug */ + // For performance, we verify stack size only on compilation time (mjit_compile.inc.erb) without --jit-debug if (!mjit_opts.debug) { fprintf(f, "#undef OPT_CHECKED_RUN\n"); fprintf(f, "#define OPT_CHECKED_RUN 0\n\n"); @@ -242,8 +242,8 @@ mjit_compile(FILE *f, const rb_iseq_t *i https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L242 fprintf(f, " static const VALUE *const original_body_iseq = (VALUE *)0x%"PRIxVALUE";\n", (VALUE)body->iseq_encoded); - /* Simulate `opt_pc` in setup_parameters_complex. Other PCs which may be passed by catch tables - are not considered since vm_exec doesn't call mjit_exec for catch tables. */ + // Simulate `opt_pc` in setup_parameters_complex. Other PCs which may be passed by catch tables + // are not considered since vm_exec doesn't call mjit_exec for catch tables. if (body->param.flags.has_opt) { int i; fprintf(f, "\n"); @@ -262,4 +262,4 @@ mjit_compile(FILE *f, const rb_iseq_t *i https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L262 return status.success; } -#endif /* USE_MJIT */ +#endif // USE_MJIT Index: mjit_worker.c =================================================================== --- mjit_worker.c (revision 67532) +++ mjit_worker.c (revision 67533) @@ -6,9 +6,9 @@ https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L6 **********************************************************************/ -/* NOTE: All functions in this file are executed on MJIT worker. So don't - call Ruby methods (C functions that may call rb_funcall) or trigger - GC (using ZALLOC, xmalloc, xfree, etc.) in this file. */ +// NOTE: All functions in this file are executed on MJIT worker. So don't +// call Ruby methods (C functions that may call rb_funcall) or trigger +// GC (using ZALLOC, xmalloc, xfree, etc.) in this file. /* We utilize widely used C compilers (GCC and LLVM Clang) to implement MJIT. We feed them a C code generated from ISEQ. The @@ -97,7 +97,7 @@ https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L97 #include "dln.h" #include "ruby/util.h" -#undef strdup /* ruby_strdup may trigger GC */ +#undef strdup // ruby_strdup may trigger GC #ifndef MAXPATHLEN # define MAXPATHLEN 1024 @@ -117,41 +117,41 @@ https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L117 typedef intptr_t pid_t; #endif -/* Atomically set function pointer if possible. */ +// Atomically set function pointer if possible. #define MJIT_ATOMIC_SET(var, val) (void)ATOMIC_PTR_EXCHANGE(var, val) #define MJIT_TMP_PREFIX "_ruby_mjit_" -/* The unit structure that holds metadata of ISeq for MJIT. */ +// The unit structure that holds metadata of ISeq for MJIT. struct rb_mjit_unit { - /* Unique order number of unit. */ + // Unique order number of unit. int id; - /* Dlopen handle of the loaded object file. */ + // Dlopen handle of the loaded object file. void *handle; const rb_iseq_t *iseq; #ifndef _MSC_VER - /* This value is always set for `compact_all_jit_code`. Also used for lazy deletion. */ + // This value is always set for `compact_all_jit_code`. Also used for lazy deletion. char *o_file; - /* true if it's inherited from parent Ruby process and lazy deletion should be skipped. - `o_file = NULL` can't be used to skip lazy deletion because `o_file` could be used - by child for `compact_all_jit_code`. */ + // true if it's inherited from parent Ruby process and lazy deletion should be skipped. + // `o_file = NULL` can't be used to skip lazy deletion because `o_file` could be used + // by child for `compact_all_jit_code`. bool o_file_inherited_p; #endif #if defined(_WIN32) - /* DLL cannot be removed while loaded on Windows. If this is set, it'll be lazily deleted. */ + // DLL cannot be removed while loaded on Windows. If this is set, it'll be lazily deleted. char *so_file; #endif - /* Only used by unload_units. Flag to check this unit is currently on stack or not. */ + // Only used by unload_units. Flag to check this unit is currently on stack or not. char used_code_p; struct list_node unode; // mjit_compile's optimization switches struct rb_mjit_compile_info compile_info; }; -/* Linked list of struct rb_mjit_unit. */ +// Linked list of struct rb_mjit_unit. struct rb_mjit_unit_list { struct list_head head; - int length; /* the list length */ + int length; // the list length }; extern void rb_native_mutex_lock(rb_nativethread_lock_t *lock); @@ -165,12 +165,12 @@ extern void rb_native_cond_signal(rb_nat https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L165 extern void rb_native_cond_broadcast(rb_nativethread_cond_t *cond); extern void rb_native_cond_wait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex); -/* process.c */ +// process.c extern rb_pid_t ruby_waitpid_locked(rb_vm_t *, rb_pid_t, int *status, int options, rb_nativethread_cond_t *cond); -/* A copy of MJIT portion of MRI options since MJIT initialization. We - need them as MJIT threads still can work when the most MRI data were - freed. */ +// A copy of MJIT portion of MRI options since MJIT initialization. We +// need them as MJIT threads still can work when the most MRI data were +// freed. struct mjit_options mjit_opts; // true if MJIT is enabled. @@ -179,28 +179,28 @@ bool mjit_enabled = false; https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L179 // and `mjit_call_p == false`, any JIT-ed code execution is cancelled as soon as possible. bool mjit_call_p = false; -/* Priority queue of iseqs waiting for JIT compilation. - This variable is a pointer to head unit of the queue. */ +// Priority queue of iseqs waiting for JIT compilation. +// This variable is a pointer to head unit of the queue. static struct rb_mjit_unit_list unit_queue = { LIST_HEAD_INIT(unit_queue.head) }; -/* List of units which are successfully compiled. */ +// List of units which are successfully compiled. static struct rb_mjit_unit_list active_units = { LIST_HEAD_INIT(active_units.head) }; -/* List of compacted so files which will be cleaned up by `free_list()` in `mjit_finish()`. */ +// List of compacted so files which will be cleaned up by `free_list()` in `mjit_finish()`. static struct rb_mjit_unit_list compact_units = { LIST_HEAD_INIT(compact_units.head) }; // List of units before recompilation and just waiting for dlclose(). static struct rb_mjit_unit_list stale_units = { LIST_HEAD_INIT(stale_units.head) }; -/* The number of so far processed ISEQs, used to generate unique id. */ +// The number of so far processed ISEQs, used to generate unique id. static int current_unit_num; -/* A mutex for conitionals and critical sections. */ +// A mutex for conitionals and critical sections. static rb_nativethread_lock_t mjit_engine_mutex; -/* A thread conditional to wake up `mjit_finish` at the end of PCH thread. */ +// A thread conditional to wake up `mjit_finish` at the end of PCH thread. static rb_nativethread_cond_t mjit_pch_wakeup; -/* A thread conditional to wake up the client if there is a change in - executed unit status. */ +// A thread conditional to wake up the client if there is a change in +// executed unit status. static rb_nativethread_cond_t mjit_client_wakeup; -/* A thread conditional to wake up a worker if there we have something - to add or we need to stop MJIT engine. */ +// A thread conditional to wake up a worker if there we have something +// to add or we need to stop MJIT engine. static rb_nativethread_cond_t mjit_worker_wakeup; -/* A thread conditional to wake up workers if at the end of GC. */ +// A thread conditional to wake up workers if at the end of GC. static rb_nativethread_cond_t mjit_gc_wakeup; // True when GC is working. static bool in_gc; @@ -211,31 +211,31 @@ static bool stop_worker_p; https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L211 // Set to true if worker is stopped. static bool worker_stopped; -/* Path of "/tmp", which can be changed to $TMP in MinGW. */ +// Path of "/tmp", which can be changed to $TMP in MinGW. static char *tmp_dir; -/* Hash like { 1 => true, 2 => true, ... } whose keys are valid `class_serial`s. - This is used to invalidate obsoleted CALL_CACHE. */ +// Hash like { 1 => true, 2 => true, ... } whose keys are valid `class_serial`s. +// This is used to invalidate obsoleted CALL_CACHE. static VALUE valid_class_serials; -/* Used C compiler path. */ +// Used C compiler path. static const char *cc_path; -/* Used C compiler flags. */ +// Used C compiler flags. static const char **cc_common_args; -/* Name of the precompiled header file. */ +// Name of the precompiled header file. static char *pch_file; -/* The process id which should delete the pch_file on mjit_finish. */ +// The process id which should delete the pch_file on mjit_finish. static rb_pid_t pch_owner_pid; -/* Status of the precompiled header creation. The status is - shared by the workers and the pch thread. */ +// Status of the precompiled header creation. The status is +// shared by the workers and the pch thread. static enum {PCH_NOT_READY, PCH_FAILED, PCH_SUCCESS} pch_status; #ifndef _MSC_VER -/* Name of the header file. */ +// Name of the header file. static char *header_file; #endif #ifdef _WIN32 -/* Linker option to enable libruby. */ +// Linker option to enable libruby. static char *libruby_pathflag; #endif @@ -256,7 +256,7 @@ static char *libruby_pathflag; https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L256 #if defined __GNUC__ && !defined __clang__ && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(_AIX) && !defined(__OpenBSD__) # define GCC_NOSTDLIB_FLAGS "-nodefaultlibs", "-nostdlib", #else -# define GCC_NOSTDLIB_FLAGS /* empty */ +# define GCC_NOSTDLIB_FLAGS // empty #endif static const char *const CC_COMMON_ARGS[] = { @@ -291,8 +291,8 @@ static const char *const CC_LIBS[] = { https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L291 #define CC_CODEFLAG_ARGS (mjit_opts.debug ? CC_DEBUG_ARGS : CC_OPTIMIZE_ARGS) -/* Print the arguments according to FORMAT to stderr only if MJIT - verbose option value is more or equal to LEVEL. */ +// Print the arguments according to FORMAT to stderr only if MJIT +// verbose option value is more or equal to LEVEL. PRINTF_ARGS(static void, 2, 3) verbose(int level, const char *format, ...) { @@ -301,7 +301,7 @@ verbose(int level, const char *format, . https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L301 size_t len = strlen(format); char *full_format = alloca(sizeof(char) * (len + 2)); - /* Creating `format + '\n'` to atomically print format and '\n'. */ + // Creating `format + '\n'` to atomically print format and '\n'. memcpy(full_format, format, len); full_format[len] = '\n'; full_format[len+1] = '\0'; @@ -326,8 +326,8 @@ mjit_warning(const char *format, ...) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L326 } } -/* Add unit node to the tail of doubly linked LIST. It should be not in - the list before. */ +// Add unit node to the tail of doubly linked `list`. It should be not in +// the list before. static void add_to_list(struct rb_mjit_unit *unit, struct rb_mjit_unit_list *list) { @@ -360,7 +360,7 @@ remove_file(const char *filename) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L360 } } -/* Lazily delete .o and/or .so files. */ +// Lazily delete .o and/or .so files. static void clean_object_files(struct rb_mjit_unit *unit) { @@ -369,8 +369,8 @@ clean_object_files(struct rb_mjit_unit * https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L369 char *o_file = unit->o_file; unit->o_file = NULL; - /* For compaction, unit->o_file is always set when compilation succeeds. - So save_temps needs to be checked here. */ + // For compaction, unit->o_file is always set when compilation succeeds. + // So save_temps needs to be checked here. if (!mjit_opts.save_temps && !unit->o_file_inherited_p) remove_file(o_file); free(o_file); @@ -389,30 +389,29 @@ clean_object_files(struct rb_mjit_unit * https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L389 #endif } -/* This is called in the following situations: - 1) On dequeue or `unload_units()`, associated ISeq is already GCed. - 2) The unit is not called often and unloaded by `unload_units()`. - 3) Freeing lists on `mjit_finish()`. - - `jit_func` value does not matter for 1 and 3 since the unit won't be used anymore. - For the situation 2, this sets the ISeq's JIT state to NOT_COMPILED_JIT_ISEQ_FUNC - to prevent the situation that the same methods are continuously compiled. */ +// This is called in the following situations: +// 1) On dequeue or `unload_units()`, associated ISeq is already GCed. +// 2) The unit is not called often and unloaded by `unload_units()`. +// 3) Freeing lists on `mjit_finish()`. +// +// `jit_func` value does not matter for 1 and 3 since the unit won't be used anymore. +// For the situation 2, this sets the ISeq's JIT state to NOT_COMPILED_JIT_ISEQ_FUNC +// to prevent the situation that the same methods are continuously compiled. static void free_unit(struct rb_mjit_unit *unit) { - if (unit->ise (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/