Home »

Archives

Subscribe

Archives

Categories

Attribution-NonCommercial-ShareAlike 4.0 International

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.

An Empirical Study on the Use and Misuse of Java 8 Streams

Introduction

Streaming APIs allow for big data processing of native data structures by providing MapReduce-like operations over these structures. However, unlike traditional big data systems, these data structures typically reside in shared memory accessed by multiple cores. Although popular, this emerging hybrid paradigm opens the door to possibly detrimental behavior, such as thread contention and bugs related to non-execution and non-determinism. This study explores the use and misuse of a popular streaming API, namely, Java 8 Streams. The focus is on how developers decide whether or not to run these operations sequentially or in parallel and bugs both specific and tangential to this paradigm. Our study involved analyzing 34 Java projects and 5.53 million lines of code, along with 719 manually examined code patches. Various automated, including interprocedural static analysis, and manual methodologies were employed. The results indicate that streams are pervasive, stream parallelization is not widely used, and performance is a crosscutting concern that accounted for the majority of fixes. We also present coincidences that both confirm and contradict the results of related studies. The study advances our understanding of streams, as well as benefits practitioners, programming language and API designers, tool developers, and educators alike.

Researchers

Name Affiliation
Raffi Khatchadourian City University of New York (CUNY) Hunter College
Yiming Tang City University of New York (CUNY) Graduate Center
Mehdi Bagherzadeh Oakland University
Baishakhi Ray Columbia University

Publications

My and my research students‘ names are boldfaced, undergraduate students are italicized, and female students are underlined:

Raffi KhatchadourianYiming Tang, Mehdi Bagherzadeh, and Baishakhi Ray. An empirical study on the use and misuse of Java 8 streams. In Heike Wehrheim and Jordi Cabot, editors, Fundamental Approaches to Software Engineering, FASE ’20, pages 97–118, Cham, April 2020. ETAPS, Springer International Publishing. (23/81; 28% acceptance rate). EAPLS Best Paper Award 🏆. [ bib | DOI | data | slides | http ]

Study Data

Subject Source Code

The set of open-source Java projects packaged as Eclipse projects used in the stream usage and characteristics studies can be downloaded as an archive. Please refer to the included README.md file for building instructions and the LICENSE.md file for licensing information. Subject source code and version history for the stream bug study can be downloaded directly from GitHub.

Raw Results

The data set consisting of the raw results produced during our study can be found on Zenodo. The directory structure is as follows:

  • characteristics_subject_data.csv: General attributes of the subjects used for the stream characteristics analysis.
  • Column subject raw may be the subproject for several subjects.
  • Some metrics, e.g., SLOC, are only associated with the first subproject for a given subject.
  • characteristics_subject_ages.csv: Ages of the subjects used for the stream characteristics analysis.
  • characteristics_subject_entry_points.csv: Detailed info on entry points used in the analysis of the characteristics.
  • characteristics_stream_execution_modes.csv: Stream execution modes.
  • characteristics_stream_orderings.csv: Stream orderings.
  • characteristics_stream_attributes.csv: Stream side-effects and stateful intermediate operations (SIOs).
  • method_calls.csv: Raw data for the stream operation analysis.
  • method_calls_subjects.csv: Data on the subjects used for the method call analysis.
  • bugs.csv: Raw data for the stream bug study.

Presentations

Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams

Introduction

Screenshot

The Java 8 Stream API sets forth a promising new programming model that incorporates functional-like, MapReduce-style features into a mainstream programming language. However, using streams efficiently may involve subtle considerations. For example, although streams enable developers to run their code in parallel with little alteration, it is often not obvious if such code runs more efficiently this way. In fact, under certain conditions, running stream code in parallel can be less efficient than running it sequentially. Moreover, it can be unclear if running sequential stream code in parallel is safe and interference-free due to possible lambda expression side-effects.

This project involves an automated refactoring approach that assists developers in writing optimal stream client code in a semantics-preserving fashion. The approach, based on a novel data ordering and typestate analysis, consists of refactorings that include preconditions and transformations for automatically determining when it is safe and possibly advantageous to convert a sequential stream to parallel and improve upon already parallel streams. The approach is implemented as a plug-in to the popular Eclipse IDE utilizing both WALA and SAFE.

Researchers

Name Affiliation
Raffi Khatchadourian City University of New York (CUNY) Hunter College
Yiming Tang City University of New York (CUNY) Graduate Center
Mehdi Bagherzadeh Oakland University
Syed Ahmed Oakland University

Publications

My and my research students‘ names appear in boldface. Undergraduate students appear in italics.

Raffi KhatchadourianYiming Tang, and Mehdi Bagherzadeh. Safe automated refactoring for intelligent parallelization of Java 8 streams. Science of Computer Programming, 195:102476, 2020. [ bib | DOI | http ]

Raffi KhatchadourianYiming Tang, Mehdi Bagherzadeh, and Syed Ahmed. Safe automated refactoring for intelligent parallelization of Java 8 streams. Technical Report 544, City University of New York (CUNY) Hunter College, 695 Park Ave, New York, NY 10065 United States, July 2019. [ bib | http ]

Raffi KhatchadourianYiming Tang, Mehdi Bagherzadeh, and Syed Ahmed. Safe automated refactoring for intelligent parallelization of Java 8 streams. In International Conference on Software Engineering, ICSE ’19, pages 619–630, Piscataway, NJ, USA, May 2019. ACM/IEEE, IEEE Press. (109/529; 20.6% acceptance rate). [ bib | DOI | tool | slides | http ]

Raffi KhatchadourianYiming Tang, Mehdi Bagherzadeh, and Syed Ahmed. A tool for optimizing Java 8 stream software via automated refactoring. In International Working Conference on Source Code Analysis and Manipulation, SCAM ’18. IEEE, September 2018. (9/17; 53% acceptance rate). Best paper award. [ bib | tool | slides | http ]

Yiming TangRaffi Khatchadourian, Mehdi Bagherzadeh, and Syed Ahmed. Towards safe refactoring for intelligent parallelization of Java 8 streams. In International Conference on Software Engineering: Companion Proceeedings, ICSE ’18, pages 206–207, New York, NY, USA, May 2018. ACM/IEEE, ACM. [ bib | DOI | poster | http ]

Research Prototype

Our research prototype may be found on GitHub.

Supporting Repositories

Study Data

Subject Descriptions

Subject Version Description
htm.java 0.6.13 Hierarchical Temporal Memory implementation in Java – an official Community-Driven Java port of the Numenta Platform for Intelligent Computing (NuPIC).
JacpFX 2.1 An API to create Rich Clients in MVC style with JavaFX, Spring (or other DI frameworks) and an Actor like component approach.
java-design-patterns 1.12.0 (bc94d0f) Design patterns implemented in Java.
jdk8-experiments 3c7d717 An personal repository for experimentation with the new JDK 8 features.
jetty.project 9.4.8 Eclipse Jetty – Web Container & Clients – supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more.
jOOQ 3.10.4 jOOQ is the best way to write SQL in Java.
koral Scientific publishing with HTML.
monads 0.5 Basic monads for Java.
retrolambda 2.5.3 Backport of Java 8’s lambda expressions to Java 7, 6 and 5.
streamql 0.5.8 A query tool for java.util.stream.Stream.
ThreeTen Extra 1.3.2 Provide additional date-time classes that complement those in JDK 8.

Subject Source Code

The set of open-source Java projects packaged as Eclipse projects used for assessing our refactoring can be downloaded as an archive. Please refer to the included README.md file for building instructions and the LICENSE.md file for licensing information.

Raw Results

The data set consisting of the raw results produced during our study can be found on Zenodo.

Scripts used to produce the results can be found in our prototype implementation repository. htm_java.sh and jmh_profile.sh are the scripts used to execute the performance evaluation of htm.java and java-design-patterns, respectively. They assume that separate git branches are used to store the original source code and the refactored source code; these can be created using the above-mentioned patch files and git. mvn_check.sh, which also assumes the same git structure, is used to verify that the same test results exist before and after the refactoring. It can be easily adapted for projects that use Gradle.

Presentations