1. An apparatus for generating code for a virtual machine, the apparatus comprising: a processor; an interpreter implemented by the processor and configured to execute bytecode of a virtual machine; an information collecting unit implemented by the processor and configured to collect tracking information indicating a logical flow of execution of the bytecode by the interpreter, and to collect a number of executions of the bytecode by the interpreter; and a compiler implemented by the processor, the compiler configured to compile the bytecode into machine code, the compiler comprising: a work queue configured to store bytecode sections to be translated into machine code; and a code determining unit configured to receive the collected tracking information and to determine whether the compiler is idle, wherein in response to the compiler being idle, divide the bytecode into bytecode segments having a predefined length, based on the logical flow of execution of the bytecode; determine a bytecode trace among the bytecode segments, based on the number of executions of the bytecode, wherein the bytecode trace has the predefined length, and wherein the bytecode trace comprises a starting point that is a bytecode segment that has been executed by the interpreter more than a threshold number of executions; and compile the bytecode into machine code: and in response to the compiler not being idle, receive the collected tracking information, wherein the information collecting unit is implemented separately from both the interpreter and the compiler, and wherein the predefined length of the bytecode trace is defined based on a capacity of the work queue and a capacity of a code cache.