Example #1
0
 def __init__(self, result, cls_name, field_type, field_name):
     super(StaticExpression, self).__init__()
     self.value = result
     self.cls = util.get_type(cls_name)
     self.ftype = field_type
     self.name = field_name
     self.clsdesc = cls_name
Example #2
0
 def visit_landing_pad(self, landing_pad):
     self.write("%s:\n" % (landing_pad.label))
     self.write("D2C_GET_PENDING_EX\n")
     for atype, handle in landing_pad.handles.items():
         self.write('if(d2c_is_instance_of(env, exception, "%s")) {\n' % (get_type(atype)))
         self.write('goto L%d;\n' % handle.num)
         self.write('}\n')
     self.write("D2C_GOTO_UNWINDBLOCK\n")
Example #3
0
 def __init__(self, rhs, klass, ftype, name):
     super(StaticInstruction, self).__init__()
     self.cls = util.get_type(klass)
     self.ftype = ftype
     self.name = name
     self.clsdesc = klass
     rhs.add_user(self)
     self.operands.append(rhs)
Example #4
0
 def visit_instanceof(self, ins, result, arg, atype):
     self.write_trace(ins)
     self.write('{\n')
     self.write_define_ex_handle(ins)
     self.write('jclass &clz = %s;\n' % (self.ca(ins.get_class())))
     self.write('D2C_RESOLVE_CLASS(clz,"%s");\n' % (get_type(atype)))
     self.write('v%s = d2c_is_instance_of(env, v%s, clz);\n' % (self.ra(result), self.ra(arg)))
     self.write_undefine_ex_handle(ins)
     self.write('}\n')
Example #5
0
 def visit_check_cast(self, ins, arg, atype):
     self.write_trace(ins)
     self.write('{\n')
     self.write_define_ex_handle(ins)
     self.write('jclass &clz = %s;\n' % (self.ca(ins.get_class())))
     self.write('D2C_RESOLVE_CLASS(clz,"%s");\n' % (get_type(atype)))
     self.write('D2C_CHECK_CAST(%s, clz, "%s");\n' % (self.get_variable_or_const(arg), get_type(atype)))
     self.write_undefine_ex_handle(ins)
     self.write('}\n')
Example #6
0
    def __init__(self, result, arg, klass, ftype, name):
        super(InstanceExpression, self).__init__()
        self.value = result
        self.cls = util.get_type(klass)
        self.ftype = ftype
        self.name = name
        self.clsdesc = klass

        arg.add_user(self)
        self.operands.append(arg)
Example #7
0
    def _invoke_common(self, ins, invoke_type, name, base, ptype, rtype, args, clsdesc):
        self.write('{\n')
        self.write_define_ex_handle(ins)
        if invoke_type != 'static':
            self.write("D2C_NOT_NULL(v%s);\n" % (self.ra(base)))
        self.write('jclass &clz = %s;\n' % (self.ca(ins.get_class())))
        self.write('jmethodID &mid = %s;\n' % (self.ma(ins.get_call_method())))
        if invoke_type != 'static':
            self.write('D2C_RESOLVE_METHOD(clz, mid, "%s", "%s", "(%s)%s");\n' % (get_type(clsdesc), name, ''.join(ptype), rtype))
        else:
            self.write('D2C_RESOLVE_STATIC_METHOD(clz, mid, "%s", "%s", "(%s)%s");\n' % (get_type(clsdesc), name, ''.join(ptype), rtype))
        self.write('jvalue args[] = {')
        vars = []
        for arg, atype in zip(args, ptype):
            if atype[0] == 'L' or atype[0] == '[':
                vars.append('{.l = %s}' % (self.get_variable_or_const(arg)))
            elif atype[0] == 'Z':
                vars.append('{.z = (jboolean) %s}' % (self.get_variable_or_const(arg)))
            elif atype[0] == 'B':
                vars.append('{.b = (jbyte) %s}' % (self.get_variable_or_const(arg)))
            elif atype[0] == 'C':
                vars.append('{.c = (jchar) %s}' % (self.get_variable_or_const(arg)))
            elif atype[0] == 'S':
                vars.append('{.s = (jshort) %s}' % (self.get_variable_or_const(arg)))
            elif atype[0] == 'I':
                vars.append('{.i = %s}' % (self.get_variable_or_const(arg)))
            elif atype[0] == 'J':
                vars.append('{.j = (jlong) %s}' % (self.get_variable_or_const(arg)))
            elif atype[0] == 'F':
                vars.append('{.f = %s}' % (self.get_variable_or_const(arg)))
            elif atype[0] == 'D':
                vars.append('{.d = %s}' % (self.get_variable_or_const(arg)))
            else:
                raise Exception("Unknow signuare type %s" % (atype))
        self.write(','.join(vars))
        self.write('};\n')
        if rtype != 'V':
            self.write_kill_local_reference(ins.get_value())
            ins.get_value().visit(self)
            self.write(' = ')
            self.write("(%s) " % (get_native_type(ins.get_value().get_type())))

        if invoke_type == 'super':
            self.write(
                'env->CallNonvirtual%sMethodA(v%s, clz, mid, args);\n' % (get_type_descriptor(rtype), self.ra(base)))
        elif invoke_type == 'static':
            self.write('env->CallStatic%sMethodA(clz, mid, args);\n' % (get_type_descriptor(rtype)))
        else:
            self.write('env->Call%sMethodA(v%s, mid, args);\n' % (get_type_descriptor(rtype), self.ra(base)))

        self.write_undefine_ex_handle(ins)
        self.write('}\n')
        if rtype != 'V':
            self.write_delete_dead_local_reference(ins.get_value())
Example #8
0
 def visit_put_static(self, ins, clsdesc, name, ftype, rhs):
     self.write_trace(ins)
     self.write('{\n')
     self.write_define_ex_handle(ins)
     self.write('jclass &clz = %s;\n' % (self.ca(ins.get_class())))
     self.write('jfieldID &fld = %s;\n' % (self.fa(ins.get_field())))
     self.write('D2C_RESOLVE_STATIC_FIELD(clz, fld, "%s", "%s", "%s");\n' % (get_type(clsdesc), name, ftype))
     self.write('env->SetStatic%sField(clz,fld,(%s) %s);\n' % (
         get_type_descriptor(ftype), get_native_type(ftype), self.get_variable_or_const(rhs)))
     self.write_undefine_ex_handle(ins)
     self.write('}\n')
Example #9
0
    def __init__(self, rhs, lhs, klass, atype, name):
        super(InstanceInstruction, self).__init__()
        self.atype = atype
        self.cls = util.get_type(klass)
        self.name = name
        self.clsdesc = klass

        lhs.add_user(self)
        rhs.add_user(self)
        self.operands.append(lhs)
        self.operands.append(rhs)
Example #10
0
 def visit_new(self, ins, result, atype):
     self.write_trace(ins)
     self.write('{\n')
     self.write_define_ex_handle(ins)
     # should kill local reference after D2C_RESOLVE_CLASS, since D2C_RESOLVE_CLASS may throw exception,
     # so this ref may be double killed in exception handle.
     self.write_kill_local_reference(ins.get_value())
     self.write('jclass &clz = %s;\n' % (self.ca(ins.get_class())))
     self.write('D2C_RESOLVE_CLASS(clz,"%s");\n' % (get_type(atype)))
     self.write('v%s = (%s) env->AllocObject(clz);\n' % (self.ra(result), get_native_type(result.get_type())))
     self.write_undefine_ex_handle(ins)
     self.write('}\n')
Example #11
0
 def visit_get_static(self, ins, result, ftype, clsdesc, name):
     self.write_trace(ins)
     self.write('{\n')
     self.write_define_ex_handle(ins)
     self.write_kill_local_reference(result)
     self.write('jclass &clz = %s;\n' % (self.ca(ins.get_class())))
     self.write('jfieldID &fld = %s;\n' % (self.fa(ins.get_field())))
     self.write('D2C_RESOLVE_STATIC_FIELD(clz, fld, "%s", "%s", "%s");\n' % (get_type(clsdesc), name, ftype))
     result.visit(self)
     self.write(' = (%s) env->GetStatic%sField(clz,fld);\n' % (
         get_native_type(result.get_type()), get_type_descriptor(ftype)))
     self.write_undefine_ex_handle(ins)
     self.write('}\n')
Example #12
0
 def visit_new_array(self, ins, result, atype, size):
     self.write_trace(ins)
     elem_type = ins.get_elem_type()
     self.write('{\n')
     self.write_define_ex_handle(ins)
     self.write_check_array_size(size)
     self.write_kill_local_reference(ins.get_value())
     if is_primitive_type(elem_type):
         result.visit(self)
         self.write(
             ' = (%s) env->New%sArray((jint) %s);\n' % (
             get_native_type(result.get_type()), get_type_descriptor(elem_type), self.get_variable_or_const(size)))
     else:
         self.write('jclass &clz = %s;\n' % (self.ca(ins.get_class())))
         self.write('D2C_RESOLVE_CLASS(clz,"%s");\n' % (get_type(elem_type)))
         result.visit(self)
         self.write(' = env->NewObjectArray((jint) %s, clz, NULL);\n' % (self.get_variable_or_const(size)))
     self.write_undefine_ex_handle(ins)
     self.write('}\n')
Example #13
0
 def visit_filled_new_array(self, ins, result, atype, size, args):
     self.write_trace(ins)
     params = []
     for arg in args:
         p = '%s' % (self.get_variable_or_const(arg))
         params.append(p)
     self.write('{\n')
     self.write_define_ex_handle(ins)
     self.write_kill_local_reference(ins.get_value())
     elem_type = atype[1:]
     assert elem_type != 'D' and elem_type != 'J'
     if is_primitive_type(elem_type):
         result.visit(self)
         self.write(' = env->New%sArray((jint) %r);\n' % (get_type_descriptor(elem_type), size))
     else:
         self.write('jclass &clz = %s;\n' % (self.ca(ins.get_class())))
         self.write('D2C_RESOLVE_CLASS(clz,"%s");\n' % (get_type(elem_type)))
         result.visit(self)
         self.write(' = env->NewObjectArray((jint) %r, clz, NULL);\n' % (size))
     self.write('d2c_filled_new_array(env, (jarray) v%s, "%s", %d, %s);\n'
                % (self.ra(result), elem_type, len(params), ', '.join(params)))
     self.write_undefine_ex_handle(ins)
     self.write('}\n')