Class: Maglev::Reflection::ThreadMirror

Inherits:
Ruby::Reflection::ThreadMirror show all
Defined in:
lib/maglev/reflection/thread_mirror.rb

Defined Under Namespace

Classes: StackFrame

Constant Summary collapse

ExceptionHandlers =
{}

Instance Attribute Summary

Attributes included from AbstractReflection::Mirror

#reflection

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Ruby::Reflection::ThreadMirror

#return_value, #status

Methods included from AbstractReflection::ThreadMirror

#breakpoints, #compiler, #kill, #return_value, #status, #stop

Methods included from AbstractReflection::Mirror

#initialize, #mirrors?, #name, #reflectee

Methods included from AbstractReflection::Mirror::ClassMethods

#included, #mirror_class, #new, #reflect, #reflect!, #reflects?, #register_mirror

Methods inherited from Ruby::Reflection::ObjectMirror

#target_class, #variables

Methods included from AbstractReflection::ObjectMirror

#class_variables, #instance_eval, #objects_with_references, #path_to, #target_class, #transitive_closure, #variables

Class Method Details

.copy_active_threadObject



13
14
15
# File 'lib/maglev/reflection/thread_mirror.rb', line 13

def self.copy_active_thread
  save_thread("Continuation #{Thread.current}").continuation
end

Instance Method Details

#call(arg) ⇒ Object



109
110
111
112
113
# File 'lib/maglev/reflection/thread_mirror.rb', line 109

def call(arg)
  if @subject.__is_partial_continuation
    Thread.__installPartialContinuation_atLevel_value(@subject, 1, arg)
  end
end

#compiler_stateObject



79
80
81
# File 'lib/maglev/reflection/thread_mirror.rb', line 79

def compiler_state
  thread_data.first
end

#handle_exception(e = Exception, &block) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/maglev/reflection/thread_mirror.rb', line 57

def handle_exception(e = Exception, &block)
  ExceptionHandlers[@subject.object_id] ||= []
  ExceptionHandlers[@subject.object_id] << proc do |ex|
    block[ex] if [*e].any? {|ec| ex.is_a? ec }
  end

  Exception.install_debug_block do |ex|
    if handlers = ExceptionHandlers[Thread.current.object_id]
      handlers.each {|h| h[ex] }
    end
  end
end

#raw_stackObject

Maglev specific… for now



71
72
73
# File 'lib/maglev/reflection/thread_mirror.rb', line 71

def raw_stack
  stack # Force cache refresh
end

#reset(block = Proc.new) ⇒ Object



105
106
107
# File 'lib/maglev/reflection/thread_mirror.rb', line 105

def reset(block = Proc.new)
  (proc { block.call }).call
end

#runObject



30
31
32
33
34
35
# File 'lib/maglev/reflection/thread_mirror.rb', line 30

def run
  if @subject.__is_continuation
    Thread.start { @subject.__value(nil) }.run
  end
  super
end

#shift(block = Proc.new) ⇒ Object

Raises:

  • (RuntimeError)


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/maglev/reflection/thread_mirror.rb', line 83

def shift(block = Proc.new)
  cm = self.method(:reset).__st_gsmeth
  markLevel = nil
  level = 1
  idx = nil
  while aFrame = Thread.__frame_contents_at(level) and idx == nil
    idx = level if aFrame[0] == cm
    level += 1
  end
  raise(RuntimeError, "no enclosing #reset") if idx.nil?
  # from my caller to the reset caller
  partial_cc = Thread.__partialContinuationFromLevel_to(2, idx + 1)
  res = block.call(reflection.reflect(partial_cc))

  # Now, return execution to the reset: call and replace the
  # top-of-stack with the result of the block

  # from reset to reset caller
  cc = Thread.__partialContinuationFromLevel_to(idx - 1, idx + 1)
  Thread.__installPartialContinuation_atLevel_value(cc, idx + 1, res)
end

#stackObject



17
18
19
20
21
22
23
# File 'lib/maglev/reflection/thread_mirror.rb', line 17

def stack
  @subject.__stack_depth.times.collect do |idx|
    method = reflection.reflect @subject.__method_at(idx + 1)
    frame = StackFrame.new method, idx + 1, self
    StackFrameMirror.reflect frame, reflection
  end
end

#step(symbol = :over) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/maglev/reflection/thread_mirror.rb', line 44

def step(symbol = :over)
  case symbol
  when :into
    @subject.__step_over_in_frame(0)
  when :over
    @subject.__step_over_in_frame(1)
  when :through
    raise NotImplementedError, "not implemented yet"
  when Fixnum
    @subject.__step_over_in_frame(symbol)
  end
end

#thread_dataObject



75
76
77
# File 'lib/maglev/reflection/thread_mirror.rb', line 75

def thread_data
  @subject.__client_data
end

#thread_report(index) ⇒ Object

Maglev specific



26
27
28
# File 'lib/maglev/reflection/thread_mirror.rb', line 26

def thread_report(index)
  @subject.__gsi_debugger_detailed_report_at(index)
end

#wakeupObject



37
38
39
40
41
42
# File 'lib/maglev/reflection/thread_mirror.rb', line 37

def wakeup
  if @subject.__is_continuation
    raise RuntimeError, "cannot wakeup a continuation with #wakeup"
  end
  super
end