Module: LLRB::JIT

Defined in:
lib/llrb/jit.rb,
ext/llrb/llrb.c

Defined Under Namespace

Classes: CompileError, ParseError

Class Method Summary collapse

Class Method Details

.compile(recv, name) ⇒ Boolean

Compile method to native code

Parameters:

  • recv (Object)
    • receiver of method to be compiled

  • method (String, Symbol)
    • precompiled method name

Returns:

  • (Boolean)
    • return true if precompiled



10
11
12
# File 'lib/llrb/jit.rb', line 10

def self.compile(recv, name)
  compile_proc(recv.method(name))
end

.compile_iseqBoolean

Return true if compiled

Returns:

  • (Boolean)

    return true if compiled



111
112
113
114
115
116
# File 'ext/llrb/llrb.c', line 111

static VALUE
rb_jit_compile_iseq(RB_UNUSED_VAR(VALUE self), VALUE iseqw)
{
  const rb_iseq_t *iseq = rb_iseqw_to_iseq(iseqw);
  return llrb_compile_iseq_to_method(iseq);
}

.compile_proc(func) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/llrb/jit.rb', line 14

def self.compile_proc(func)
  iseqw = RubyVM::InstructionSequence.of(func)
  return false if iseqw.nil? # method defined with C function can't be compiled

  #puts "#{iseqw.disasm}\n"
  compile_iseq(iseqw)
end

.compiled?(recv, name) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
# File 'lib/llrb/jit.rb', line 35

def self.compiled?(recv, name)
  method = recv.method(name)
  iseqw = RubyVM::InstructionSequence.of(method)
  return false if iseqw.nil?

  is_compiled(iseqw)
end

.is_compiledObject



118
119
120
121
122
123
# File 'ext/llrb/llrb.c', line 118

static VALUE
rb_jit_is_compiled(RB_UNUSED_VAR(VALUE self), VALUE iseqw)
{
  const rb_iseq_t *iseq = rb_iseqw_to_iseq(iseqw);
  return llrb_check_already_compiled(iseq) ? Qtrue : Qfalse;
}

.preview(recv, name) ⇒ Object

Preview compiled method in LLVM IR

Parameters:

  • recv (Object)
    • receiver of method to be compiled

  • method_name (String, Symbol)
    • precompiled method name



26
27
28
29
30
31
32
33
# File 'lib/llrb/jit.rb', line 26

def self.preview(recv, name)
  method = recv.method(name)
  iseqw = RubyVM::InstructionSequence.of(method)
  return false if iseqw.nil?

  puts "#{iseqw.disasm}\n"
  preview_iseq(iseqw)
end

.preview_iseqBoolean

Return true if compiled

Returns:

  • (Boolean)

    return true if compiled



75
76
77
78
79
80
81
82
83
84
85
# File 'ext/llrb/llrb.c', line 75

static VALUE
rb_jit_preview_iseq(RB_UNUSED_VAR(VALUE self), VALUE iseqw)
{
  const rb_iseq_t *iseq = rb_iseqw_to_iseq(iseqw);
  if (llrb_should_not_compile(iseq)) return Qfalse;

  LLVMModuleRef mod = llrb_compile_iseq(iseq->body, iseq->body->iseq_encoded, llrb_funcname);
  LLVMDumpModule(mod);
  LLVMDisposeModule(mod);
  return Qtrue;
}

.startObject



43
44
45
46
# File 'lib/llrb/jit.rb', line 43

def self.start
  hook_stop
  start_internal
end

.start_internalObject



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'ext/llrb/profiler.c', line 233

static VALUE
rb_jit_start(RB_UNUSED_VAR(VALUE self))
{
  struct sigaction sa;
  struct itimerval timer;

  if (llrb_profiler.running) return Qfalse;
  if (!llrb_profiler.sample_by_iseq) {
    llrb_profiler.sample_by_iseq = st_init_numtable();
  }

  sa.sa_sigaction = llrb_signal_handler;
  sa.sa_flags = SA_RESTART | SA_SIGINFO;
  sigemptyset(&sa.sa_mask);
  sigaction(SIGPROF, &sa, NULL);

  timer.it_interval.tv_sec = 0;
  timer.it_interval.tv_usec = LLRB_PROFILE_INTERVAL_USEC;
  timer.it_value = timer.it_interval;
  setitimer(ITIMER_PROF, &timer, 0);

  llrb_profiler.running = true;
  return Qtrue;
}

.stopObject



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'ext/llrb/profiler.c', line 258

static VALUE
rb_jit_stop(RB_UNUSED_VAR(VALUE self))
{
  struct sigaction sa;
  struct itimerval timer;

  if (!llrb_profiler.running) return Qfalse;
  llrb_profiler.running = false;

	memset(&timer, 0, sizeof(timer));
	setitimer(ITIMER_PROF, &timer, 0);

	sa.sa_handler = SIG_IGN;
	sa.sa_flags = SA_RESTART;
	sigemptyset(&sa.sa_mask);
	sigaction(SIGPROF, &sa, NULL);

  return Qtrue;
}