流 (OOP) 在汇编级别上是如何表示的?

How are streams (OOP) represented on the assembly level?

Java 的 Stream API 或 RxJava 等流如何在汇编级别表示?

I.E.

List<String> myList =
    Arrays.asList("a1", "a2", "b1", "c2", "c1");

myList
    .stream()
    .filter(s -> s.startsWith("c"))
    .map(String::toUpperCase)
    .sorted()
    .forEach(System.out::println);

这是一个非常复杂的话题,用几句话就可以涵盖。您可以从 this article by Brian Goetz 开始研究以了解 Java 流 API 的概念。之后你就可以轻松地更深入了。

首先仔细看看Spliterator抽象:

A stream source is described by an abstraction called Spliterator. As its name suggests, Spliterator combines two behaviors: accessing the elements of the source (iterating), and possibly decomposing the input source for parallel execution (splitting).

然后看看 Stream flags :

In the internal representation, each stage of the pipeline is described by a bitmap of stream flags that describe what’s known about the elements at this stage of the stream pipeline. Streams uses these flags to optimize both the construction and execution of the stream.

和 Stream 管道的执行

When the terminal operation is initiated, the stream implementation picks an execution plan.

For sequential execution, Streams constructs a “machine” — a chain of Consumer objects whose structure matches that of the pipeline structure. Each of these Consumer objects knows about the next stage; when it receives an element (or is notified that there are no more elements), it sends zero or more elements to the next stage in the chain.

然后您将能够找出每个中间操作和终端操作在 assemble 级别上的表示方式。