|
| 1 | +# README |
| 2 | + |
1 | 3 | ## LLM-Based Java Concurrent Program to ArkTS Converter |
2 | 4 |
|
| 5 | +## ABSTRACT |
| 6 | + |
| 7 | +HarmonyOS NEXT is a distributed operating system developed to |
| 8 | +support HarmonyOS native apps. To support the new and independent Harmony ecosystem, developers are required to migrate their |
| 9 | +applications from Android to HarmonyOS. However, HarmonyOS |
| 10 | +utilizes ArkTS, a superset of TypeScript, as the programming language for application development. Hence, migrating applications |
| 11 | +to HarmonyOS requires translating programs across different program languages, e.g., Java, which is known to be very challenging, |
| 12 | +especially for concurrency programs. Java utilizes shared memory to implement concurrency programs, while ArkTS relies on |
| 13 | +message passing (i.e., Actor model). This paper presents an LLMbased concurrent Java program to ArkTS converter. This converter |
| 14 | +leverages the sophisticated code comprehension and generation |
| 15 | +capabilities of large language models (LLMs) to streamline the translation process. By integrating the SharedArrayBuffer API native to |
| 16 | +ArkTS, we’ve crafted ThreadBridge, a shared library that replicates |
| 17 | +Java’s shared memory paradigm. Employing this library and LLM’s |
| 18 | +Chain-of-thought mechanism, our approach divides the translation |
| 19 | +challenge into specialized chains: the TypeScript (TS) chain, the |
| 20 | +concurrency chain, and the synchronization chain. These targeted |
| 21 | +chains are designed to efficiently translate Java’s source code into |
| 22 | +its ArkTS equivalent, handling TypeScript-specific syntax, concurrency patterns, and synchronization logic with precision. In particular, this study provides a set of effective solutions to overcome the |
| 23 | +differences in concurrency models between Java and ArkTS. With |
| 24 | +this converter, developers can reduce manual code rewriting and |
| 25 | +accelerate application adaptation and deployment on HarmonyOS |
| 26 | +NEXT. Experimental results show that our converter successfully |
| 27 | +compiles 66% of the 53 test samples, with an accuracy rate of 69% |
| 28 | +for the successfully compiled results. In conclusion, our approach |
| 29 | +demonstrates promising potential in handling the conversion of |
| 30 | +concurrent Java programs to ArkTS, providing a foundation for |
| 31 | +further improvement and optimization. |
| 32 | + |
| 33 | +### Introduce of running |
| 34 | + |
| 35 | +First you need to install LangChain and its package of openai |
| 36 | + |
| 37 | +``` |
| 38 | +pip install langchain |
| 39 | +``` |
| 40 | + |
| 41 | +``` |
| 42 | +pip install langchain-openai |
| 43 | +``` |
| 44 | + |
| 45 | +Set environment variables `OPENAI_API_KEY` to your api_key of openai. |
| 46 | + |
| 47 | +To run the AST, you need to install Java 17. |
| 48 | + |
| 49 | +To perform compilation check, you need to install tsc. |
| 50 | + |
| 51 | +Install `streamlit` library. |
| 52 | + |
| 53 | +``` |
| 54 | +pip install streamlit |
| 55 | +``` |
| 56 | + |
| 57 | +Go to LangChain directory,Enter on the command line. |
| 58 | + |
| 59 | +``` |
| 60 | +streamlit run start.py |
| 61 | +``` |
| 62 | + |
3 | 63 | demo: https://youtu.be/EPcs96vQzpg |
0 commit comments