ruby-changes:52080
From: k0kubun <ko1@a...>
Date: Sat, 11 Aug 2018 17:34:30 +0900 (JST)
Subject: [ruby-changes:52080] k0kubun:r64288 (trunk): mjit.c: exclude mjit_valid_class_serial_p
k0kubun 2018-08-11 17:34:25 +0900 (Sat, 11 Aug 2018) New Revision: 64288 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64288 Log: mjit.c: exclude mjit_valid_class_serial_p from mjit.c because it's executed only on MJIT worker thread. Instead of that, `valid_class_serials` is shared with mjit_ prefix. Modified files: trunk/mjit.c trunk/mjit.h trunk/mjit_compile.c trunk/mjit_worker.c Index: mjit_worker.c =================================================================== --- mjit_worker.c (revision 64287) +++ mjit_worker.c (revision 64288) @@ -76,8 +76,6 @@ https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L76 #include "vm_core.h" #include "mjit.h" #include "gc.h" -#include "constant.h" -#include "id_table.h" #include "ruby_assert.h" #include "ruby/thread.h" #include "ruby/util.h" @@ -208,6 +206,19 @@ static const char *const CC_LIBS[] = { https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L206 shared by the workers and the pch thread. */ enum pch_status_t mjit_pch_status; +/* Return TRUE if class_serial is not obsoleted. */ +int +mjit_valid_class_serial_p(rb_serial_t class_serial) +{ + extern VALUE mjit_valid_class_serials; + int found_p; + + CRITICAL_SECTION_START(3, "in valid_class_serial_p"); + found_p = st_lookup(RHASH_TBL_RAW(mjit_valid_class_serials), LONG2FIX(class_serial), NULL); + CRITICAL_SECTION_FINISH(3, "in valid_class_serial_p"); + return found_p; +} + /* Return the best unit from list. The best is the first high priority unit or the unit whose iseq has the biggest number of calls so far. */ Index: mjit.c =================================================================== --- mjit.c (revision 64287) +++ mjit.c (revision 64288) @@ -85,7 +85,7 @@ int mjit_in_jit; https://github.com/ruby/ruby/blob/trunk/mjit.c#L85 char *mjit_tmp_dir; /* 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; +VALUE mjit_valid_class_serials; extern const char *mjit_cc_path; extern char *mjit_pch_file; @@ -688,9 +688,9 @@ mjit_init(struct mjit_options *opts) https://github.com/ruby/ruby/blob/trunk/mjit.c#L688 rb_native_cond_initialize(&mjit_gc_wakeup); /* Initialize class_serials cache for compilation */ - valid_class_serials = rb_hash_new(); - rb_obj_hide(valid_class_serials); - rb_gc_register_mark_object(valid_class_serials); + mjit_valid_class_serials = rb_hash_new(); + rb_obj_hide(mjit_valid_class_serials); + rb_gc_register_mark_object(mjit_valid_class_serials); mjit_add_class_serial(RCLASS_SERIAL(rb_cObject)); mjit_add_class_serial(RCLASS_SERIAL(CLASS_OF(rb_vm_top_self()))); if (RCLASS_CONST_TBL(rb_cObject)) { @@ -837,7 +837,7 @@ mjit_mark(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L837 RUBY_MARK_LEAVE("mjit"); } -/* A hook to update valid_class_serials. This should NOT be used in MJIT worker. */ +/* A hook to update mjit_valid_class_serials. */ void mjit_add_class_serial(rb_serial_t class_serial) { @@ -846,10 +846,10 @@ mjit_add_class_serial(rb_serial_t class_ https://github.com/ruby/ruby/blob/trunk/mjit.c#L846 /* Do not wrap CRITICAL_SECTION here. This function is only called in main thread and guarded by GVL, and `rb_hash_aset` may cause GC and deadlock in it. */ - rb_hash_aset(valid_class_serials, LONG2FIX(class_serial), Qtrue); + rb_hash_aset(mjit_valid_class_serials, LONG2FIX(class_serial), Qtrue); } -/* A hook to update valid_class_serials. This should NOT be used in MJIT worker. */ +/* A hook to update mjit_valid_class_serials. */ void mjit_remove_class_serial(rb_serial_t class_serial) { @@ -857,18 +857,6 @@ mjit_remove_class_serial(rb_serial_t cla https://github.com/ruby/ruby/blob/trunk/mjit.c#L857 return; CRITICAL_SECTION_START(3, "in mjit_remove_class_serial"); - rb_hash_delete_entry(valid_class_serials, LONG2FIX(class_serial)); + rb_hash_delete_entry(mjit_valid_class_serials, LONG2FIX(class_serial)); CRITICAL_SECTION_FINISH(3, "in mjit_remove_class_serial"); } - -/* Return TRUE if class_serial is not obsoleted. This can be used in MJIT worker. */ -int -mjit_valid_class_serial_p(rb_serial_t class_serial) -{ - int found_p; - - CRITICAL_SECTION_START(3, "in valid_class_serial_p"); - found_p = st_lookup(RHASH_TBL_RAW(valid_class_serials), LONG2FIX(class_serial), NULL); - CRITICAL_SECTION_FINISH(3, "in valid_class_serial_p"); - return found_p; -} Index: mjit.h =================================================================== --- mjit.h (revision 64287) +++ mjit.h (revision 64288) @@ -73,7 +73,6 @@ extern struct mjit_cont *mjit_cont_new(r https://github.com/ruby/ruby/blob/trunk/mjit.h#L73 extern void mjit_cont_free(struct mjit_cont *cont); extern void mjit_add_class_serial(rb_serial_t class_serial); extern void mjit_remove_class_serial(rb_serial_t class_serial); -extern int mjit_valid_class_serial_p(rb_serial_t class_serial); /* A threshold used to reject long iseqs from JITting as such iseqs takes too much time to be compiled. */ Index: mjit_compile.c =================================================================== --- mjit_compile.c (revision 64287) +++ mjit_compile.c (revision 64288) @@ -51,6 +51,7 @@ struct case_dispatch_var { https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L51 static int has_valid_method_type(CALL_CACHE cc) { + extern int mjit_valid_class_serial_p(rb_serial_t class_serial); return GET_GLOBAL_METHOD_STATE() == cc->method_state && mjit_valid_class_serial_p(cc->class_serial) && cc->me; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/