Control Flow Flattening
controlFlowFlattening
~1.5x slower
मूल प्रोग्राम फ़्लो छिपाने के लिए कोड की संरचना बदल देता है। रैखिक कोड को switch स्टेटमेंट वाली स्टेट मशीन में बदलकर मैन्युअल विश्लेषण को कहीं ज़्यादा कठिन बना देता है।
// Before
function process() {
step1();
step2();
step3();
}
// After (flattened)
function process() {
var state = '0|1|2'.split('|'), i = 0;
while (true) {
switch (state[i++]) {
case '0': step1(); continue;
case '1': step2(); continue;
case '2': step3(); continue;
}
break;
}
}
Control flow flattening अन्य बेसिक विकल्पों और VM ऑब्फ़स्केशन दोनों के साथ अच्छी तरह जुड़ता है — VM चालू होने पर फ़्लैट की गई स्टेट मशीन आगे बाइटकोड में बदल दी जाती है।
