def execute(self, frame: Frame): cp = frame.method.get_class().constant_pool field_ref = cp.get_constant(self.index) field = field_ref.resolve_field() clazz = field.get_class() if not clazz.init_started: frame.revert_next_pc() ClassInitLogic.init_class(frame.thread, clazz) return # 如果解析后的字段不是静态字段,抛出IncompatibleClassChangeError异常 if not field.is_static(): raise RuntimeError("java.lang.IncompatibleClassChangeError") descriptor = field.descriptor slot_id = field.slot_id slots = clazz.static_vars stack = frame.operand_stack if descriptor[0] in {"Z", "B", "C", "S", "I", "J"}: stack.push_numeric(slots.get_numeric(slot_id)) elif descriptor[0] == 'F': stack.push_float(slots.get_float(slot_id)) elif descriptor[0] == 'D': stack.push_double(slots.get_double(slot_id)) elif descriptor[0] in {"L", "["}: stack.push_ref(slots.get_ref(slot_id))
def push(self, frame: Frame): # 如果栈已经满了,抛出StackOverflowError异常 if self.size >= self.max_size: raise RuntimeError("java.lang.StackOverflowError") if self.__top: frame.lower = self.__top self.__top = frame self.size += 1
def execute(self, frame: Frame): """ 从当前类的运行时常量池中找到一个类符号索引,解析这个类符号引用,拿到类数据,然后创建对象,并把对象引用推入栈顶。 :param frame: :return: """ cp = frame.method.get_class().constant_pool class_ref = cp.get_constant(self.index) clazz = class_ref.resolved_class() if not clazz.init_started: frame.revert_next_pc() ClassInitLogic.init_class(frame.thread, clazz) return if clazz.is_interface() or clazz.is_abstract(): raise RuntimeError("java.lang.InstantiationError") ref = clazz.new_object() frame.operand_stack.push_ref(ref)
def new_frame(self, max_locals, max_stack) -> Frame: return Frame(self, max_locals, max_stack)
def new_frame(self, method: Method): from rtda.Frame import Frame return Frame(self, method)
def start_JVM(): frame = Frame(100, 100) test_local_vars(frame.local_vars) test_operand_stack(frame.operand_stack)