一句话:提出基于数据顺序与类型状态分析的安全自动重构,将顺序 Stream 安全并行化或去并行化。
针对 Java 8 Stream 等流式 API 在面向对象语言中高效使用困难的问题:开发者需判断何时并行更优、何时因 lambda 副作用而不安全。本文提出一种保持语义的自动重构方法,基于数据顺序与 typestate 分析,建立前置条件,自动将顺序流安全转为并行流,或对已并行流取消排序/去并行化。该方法实现为 Eclipse IDE 插件,使用 WALA 与 SAFE 分析框架。在 11 个 Java 项目(约 642K 行代码)上评估:157 个候选流中 57 个(36.31%)可重构,性能测试平均加速 3.49 倍。结果表明该方法有助于充分发挥流代码优化潜力。
Streaming APIs are becoming more pervasive in mainstream Object-Oriented programming languages. For example, the Stream API introduced in Java 8 allows for functional-like, MapReduce-style operations in processing both finite and infinite data structures. However, using this API efficiently involves subtle considerations like determining when it is best for stream operations to run in parallel, when running operations in parallel can be less efficient, and when it is safe to run in parallel due to possible lambda expression side-effects. In this paper, we present an automated refactoring approach that assists developers in writing efficient stream code in a semantics-preserving fashion. The approach, based on a novel data ordering and typestate analysis, consists of preconditions for automatically determining when it is safe and possibly advantageous to convert sequential streams to parallel and unorder or de-parallelize already parallel streams. The approach was implemented as a plug-in to the Eclipse IDE, uses the WALA and SAFE analysis frameworks, and was evaluated on 11 Java projects consisting of ?642K lines of code. We found that 57 of 157 candidate streams (36.31%) were refactorable, and an average speedup of 3.49 on performance tests was observed. The results indicate that the approach is useful in optimizing stream code to their full potential.
@inproceedings{KhatchadourianT20,
title = {Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams},
author = {Raffi Khatchadourian and Yiming Tang and Mehdi Bagherzadeh and Syed Ahmed},
booktitle = {ICSE},
year = {2019},
doi = {10.1109/icse.2019.00072}
}