【问题标题】:Why is an array of size 64 allocatable on the stack, but 65 is not? [duplicate]为什么大小为 64 的数组可以在堆栈上分配,而 65 则不能? [复制]
【发布时间】:2015-04-30 13:47:23
【问题描述】:

在这个例子中:

public class Testbed {

private static final int SIZE = 64;

public static void main(String[] args) throws Exception {
    int limit = 10000;
    run(limit);
}

private static void run(int limit) {
    if (limit == 0) {
        return;
    }
    for (int i = 0; i < 1000; i++) {
        Object ints = new Object[SIZE];
        run(limit - 1);
    }
}
}

当使用 -verbose:gc 运行时,为什么 SIZE=64 不会产生任何 GC(即数组分配在堆栈上),但 SIZE=65 - 会?

JVM 是 7u79-2.5.5-0ubuntu1

【问题讨论】:

    标签: java jvm


    【解决方案1】:

    没关系,在这里找到答案:Declaring multiple arrays with 64 elements 1000 times faster than declaring array of 65 elements

    简而言之,某处存在可调整的限制。

    【讨论】:

      猜你喜欢
      • 2017-02-19
      • 2014-06-01
      • 2010-12-05
      • 2011-10-02
      • 2011-12-10
      • 2020-10-02
      • 2022-07-21
      • 2020-01-28
      • 2012-03-24
      相关资源
      最近更新 更多