JIT 说「内联」,具体内联到什么程度?多大的方法会被拒绝?调用点上有几种类型就不再内联了?这篇用 PrintInlining 的真实输出逐项核对,并用参数和耗时证实。
各方法的字节码大小(约): {'tiny': 4, 'medium': 105, 'medium2': 157, 'big': 521, 'work': 50, 'callShapes': 40} ;MaxInlineSize = 35、FreqInlineSize = 325(PrintFlagsFinal 的默认值见下)
默认值: {'FreqInlineSize': '325', 'InlineSmallCode': '2500', 'MaxInlineLevel': '15', 'MaxInlineSize': '35', 'MaxRecursiveInlineLevel': '1'} tier 3(C1 带 profile)编译 work() 时的内联决定:
Main::tiny inline | inline (hot)
Main::medium callee is too large | inline (hot)
Main::medium2 callee is too large | inline (hot)
Main::big callee is too large | hot method too big
tier 4(C2)编译 work() 时的内联决定:
Main::tiny inline (hot)
Main::medium inline (hot)
Main::medium2 inline (hot)
Main::big hot method too big 默认 耗时 45.18 ns/次;内联决定:{'tiny': 'inline (hot)', 'medium': 'inline (hot)', 'big': 'hot method too big', 'medium2': 'inline (hot)'}
-XX:FreqInlineSize=100 耗时 50.49 ns/次;内联决定:{'tiny': 'inline (hot)', 'medium': 'hot method too big', 'big': 'hot method too big', 'medium2': 'hot method too big'}
-XX:FreqInlineSize=1000 耗时 36.32 ns/次;内联决定:{'tiny': 'inline (hot)', 'medium': 'inline (hot)', 'big': 'inline (hot)', 'medium2': 'inline (hot)'}
-XX:MaxInlineSize=100 耗时 45.17 ns/次;内联决定:{'tiny': 'inline (hot)', 'medium': 'inline (hot)', 'big': 'hot method too big', 'medium2': 'inline (hot)'}
-XX:-Inline(完全关闭内联) 耗时 49.94 ns/次;内联决定:{'tiny': 'not an accessor', 'medium': 'not an accessor', 'big': 'hot method too big', 'medium2': 'not an accessor'}1 种接收者类型:每次调用 0.51 ns;PrintInlining 里 area() 的行:['@ 23 Main$A::area (4 bytes) inline (hot)', '@ 23 Main$Shape::area (0 bytes) no static binding'] 2 种接收者类型:每次调用 0.69 ns;PrintInlining 里 area() 的行:['@ 23 Main$A::area (4 bytes) inline (hot)', '@ 23 Main$B::area (4 bytes) inline (hot)', '@ 23 Main$Shape::area (0 bytes) no static binding'] 3 种接收者类型:每次调用 3.27 ns;PrintInlining 里 area() 的行:['@ 23 Main$Shape::area (0 bytes) no static binding', '@ 23 Main$Shape::area (0 bytes) virtual call'] 4 种接收者类型:每次调用 3.26 ns;PrintInlining 里 area() 的行:['@ 23 Main$Shape::area (0 bytes) no static binding', '@ 23 Main$Shape::area (0 bytes) virtual call']