Beispiel #1
0
def main(args):
    '''Init VM and run requested java application'''
    logging.basicConfig(filename='pyjvm.log', filemode='w',
                        level=logging.DEBUG)
    logging.basicConfig(level=logging.DEBUG)

    main_class = args.clazz[0]
    class_path = args.cp[0]
    params = args.param
    use_vm_cache = not args.no_vm_cache

    vm = None
    if use_vm_cache:
        vm = load_cached_vm(SERIALIZATION_ID)
    if vm is None:
        vm = vm_factory(class_path)
        vm.serialization_id = SERIALIZATION_ID
        if use_vm_cache:
            cache_vm(vm)
    else:
        vm.class_path = read_class_path(class_path)

    # lookup starter class & main method
    class_name = main_class.replace(".", "/")
    logger.debug("Starting with class %s", str(class_name))
    java_class = vm.get_class(class_name)
    main_method = java_class.find_method("main", "([Ljava/lang/String;)V")

    if main_method is None:
        raise Exception("main method not found")

    logger.debug("Executing main")

    # create array of strings from command line parameters
    m_args = [''] * main_method[1]
    c_args = []
    for param in params:
        ref = vm.make_heap_string(param)
        c_args.append(ref)

    heap_array = ("refarr", "java/lang/String", c_args)
    ref_arr = vm.add_to_heap(heap_array)

    array_class = vm.get_class("[Ljava/lang/String;")
    heap_item = JArray(array_class, vm)
    heap_item.values = c_args
    ref = vm.add_to_heap(heap_item)
    m_args[0] = ref

    # run main
    vm.run_vm(java_class, main_method, m_args)

    logger.debug("*** VM DONE ***")
Beispiel #2
0
def main():
    if not os.path.exists(PYJVMGUI_HOME):
        os.makedirs(PYJVMGUI_HOME)

    download_rt()

    app = QtWidgets.QApplication(sys.argv)

    '''Init VM and run requested java application'''
    logging.basicConfig(filename=os.path.join(PYJVMGUI_HOME, 'pyjvm.log'), filemode='w', level=logging.DEBUG)

    main_class = program_args.clazz[0]
    class_path = program_args.cp[0]
    params = program_args.param
    use_vm_cache = not program_args.no_vm_cache

    if program_args.clean_cache and os.path.isfile(VM_CACHE_PATH):
        print "WARNING: Cleaning vm-cache.bin (-cleancache)"
        os.remove(VM_CACHE_PATH)

    vm = None
    if use_vm_cache:
        vm = load_cached_vm(SERIALIZATION_ID)

    if vm is None:
        vm = vm_factory(class_path)
        vm.serialization_id = SERIALIZATION_ID
        if use_vm_cache:
            cache_vm(vm)
    else:
        for thread in vm.threads:
            PyJvmGui.THREAD_GUIS.append(PyJvmGui(ThreadExecutor(thread), len(PyJvmGui.THREAD_GUIS)))
        vm.class_path = read_class_path(class_path)

    # lookup starter class & main method
    class_name = main_class.replace(".", "/")
    logger.debug("Starting with class %s", str(class_name))
    java_class = vm.get_class(class_name)
    main_method = java_class.find_method("main", "([Ljava/lang/String;)V")

    if main_method is None:
        raise Exception("main method not found")

    logger.debug("Executing main")

    # create array of strings from command line parameters
    m_args = [''] * main_method[1]
    c_args = []
    for param in params:
        ref = vm.make_heap_string(param)
        c_args.append(ref)

    heap_array = ("refarr", "java/lang/String", c_args)
    ref_arr = vm.add_to_heap(heap_array)

    array_class = vm.get_class("[Ljava/lang/String;")
    heap_item = JArray(array_class, vm)
    heap_item.values = c_args
    ref = vm.add_to_heap(heap_item)
    m_args[0] = ref

    # run main
    vm.initialize_vm(java_class, main_method, m_args)

    sys.exit(app.exec_())
Beispiel #3
0
print "PyVJM test runner"
print

print "System information:"
print platform.platform()
print platform.version()
print

JAVA_HOME = os.environ.get('JAVA_HOME')
LOCAL_RT = os.path.isfile('../rt/rt.jar')
if JAVA_HOME is None and not LOCAL_RT:
    print "*** CAN NOT RUN TESTS ***"
    print "Set JAVA_HOME or init rt: see START.md for details"
    sys.exit()
print "Initializing Java Virtual Machine"
vm = vm_factory('../testcases/bin/')
print "VM is initialized"


def run(vm, klass_name):
    klass_name = klass_name.replace(".", "/")
    klass = vm.get_class(klass_name)
    main_method = klass.find_method("main", "([Ljava/lang/String;)V")
    m_args = [''] * main_method[1]
    vm.run_vm(klass, main_method, m_args)


print "TestCase1.Begin"
testcase = copy.deepcopy(vm)
run(testcase, "bytecode.CalcsTest")
print "TestCase1.End"