Re: [drlvm][jit] How to override jit compilation?
On the 0x212 day of Apache Harmony Tonny Lau wrote: 30 Oct 2006 11:03:50 +0600, Egor Pasko [EMAIL PROTECTED]: On the 0x212 day of Apache Harmony Tonny Lau wrote: Hi, I want to override some specific java methods with native fast path implementations. So I try to override them in compile_do_compilation_jit()(vm/vmcore/src/jit/compile.cpp), that is, I add several entries in _stub_override_entries_base[](vm/vmcore/src/util/ia32/base/compile_IA32.cpp), and lookup this table before invoke jit-compile_method_with_params(). This mechanism is not used (AFAIR and AFAICanSeeNow). The alternative way is to support your magics within each JIT. (Mikhail does things like that in OPT just from JavaByteCodeTranslator.cpp (see isMagicClass(...)) Thanks! I'll look it. It works for JET, but failed when OPT recompile these method. Does the OPT go different path? If so, how can I override it? Does anyone can help me? how does it fail? did you try it with -Xem:opt? (That's what I tend to always ask about:) Just a guess: OPT expects some profile from JET, but cannot find any. I mean, the overriding succeeds when I use JET only, i.e., java - Dem.properties=jet If I use the default configuration java ..., at the beginning, the overriding is successful because the code is compiled by JET. But later, when the EM invoke OPT to re-compile the hot code, the overriding does not work any longer. It fall back to the original java code. yeah, that looks much like inlining :) hence, fixable in the inliner So, where do you think is the best place in OPT for the overriding code? I suppose overriding==your-custom-native-code? Can your code be written using ordinary (address) arithmetic and simple mem allocations? If so, then the best method is to write it in Java using *org.vmmagic.unboxed* package that Mikhail has just implemented. Otherwise you can hack around JavaByteCodeTranslator::invokevirtual and recognize your magic methods there, replacing the method's invokation with your custom IR. And is there a common path for both JET and OPT? No. Especially when you take OPT's inlining into consideration. OPT can inline using only OPTs mechanisms that JET is not aware of. But *org.vmmagic.unboxed* can help you since it is supported both in JET and OPT. -- Egor Pasko, Intel Managed Runtime Division
Re: [drlvm][jit] How to override jit compilation?
Today I see several possible solutions. The complete solution with calling arbitrary native methods from Java is not ready: we are just discussing it in a separate thread. The first step of calling arbitrary native calls from Java is VM helpers inlining framework. I'm going to commit it today and will notify you about JIRA num. I hope it will serve as example. The solutions we have today: 1) If you have only a few methods to be affected: create separate JIT instance without inliner and add method filters to EM configuration file. Check http://incubator.apache.org/harmony/subcomponents/drlvm/emguide.htmland *.emconf files for details. 2) If you need to avoid inlining of special method in all Java methods you can use 'skip_methods' parameter of inliner pass. See opt.emconf file to check how to pass parameters to inliner. 3) Replace all calls to your method with VMHelperCall in translator. Process it as direct calls in codegenerator. This solution was already proposed by Egor. -- Mikhail Fursov
Re: [drlvm][jit] How to override jit compilation?
Mikhail Fursov wrote: The solutions we have today: 1) If you have only a few methods to be affected: create separate JIT instance without inliner and add method filters to EM configuration file. Check http://incubator.apache.org/harmony/subcomponents/drlvm/emguide.htmland *.emconf files for details. 2) If you need to avoid inlining of special method in all Java methods you can use 'skip_methods' parameter of inliner pass. See opt.emconf file to check how to pass parameters to inliner. 3) Replace all calls to your method with VMHelperCall in translator. Process it as direct calls in codegenerator. This solution was already proposed by Egor. For the sake of completeness, there is one more solution 4) mark methods as 'native' in java sources and provide native stub overrides in vmcore/src/jit/native_overrides.cpp.
Re: [drlvm][jit] How to override jit compilation?
On the 0x212 day of Apache Harmony Tonny Lau wrote: Hi, I want to override some specific java methods with native fast path implementations. So I try to override them in compile_do_compilation_jit()(vm/vmcore/src/jit/compile.cpp), that is, I add several entries in _stub_override_entries_base[](vm/vmcore/src/util/ia32/base/compile_IA32.cpp), and lookup this table before invoke jit-compile_method_with_params(). This mechanism is not used (AFAIR and AFAICanSeeNow). The alternative way is to support your magics within each JIT. (Mikhail does things like that in OPT just from JavaByteCodeTranslator.cpp (see isMagicClass(...)) It works for JET, but failed when OPT recompile these method. Does the OPT go different path? If so, how can I override it? Does anyone can help me? how does it fail? did you try it with -Xem:opt? (That's what I tend to always ask about:) Just a guess: OPT expects some profile from JET, but cannot find any. -- Egor Pasko, Intel Managed Runtime Division
Re: [drlvm][jit] How to override jit compilation?
Tonny, Tonny Lau wrote: Hi, I want to override some specific java methods with native fast path implementations. So I try to override them in compile_do_compilation_jit()(vm/vmcore/src/jit/compile.cpp), that is, I add several entries in _stub_override_entries_base[](vm/vmcore/src/util/ia32/base/compile_IA32.cpp), and lookup this table before invoke jit-compile_method_with_params(). It works for JET, but failed when OPT recompile these method. Does the OPT go different path? I suppose it's because OPT inlines the methods of your interest, so they simply do not go through the VM's compilation machinery. If so, how can I override it? Does anyone can help me? Try to turn off inlining in OPT - will it help? -- Thanks, Alex
Re: [drlvm][jit] How to override jit compilation?
30 Oct 2006 11:03:50 +0600, Egor Pasko [EMAIL PROTECTED]: On the 0x212 day of Apache Harmony Tonny Lau wrote: Hi, I want to override some specific java methods with native fast path implementations. So I try to override them in compile_do_compilation_jit()(vm/vmcore/src/jit/compile.cpp), that is, I add several entries in _stub_override_entries_base[](vm/vmcore/src/util/ia32/base/compile_IA32.cpp), and lookup this table before invoke jit-compile_method_with_params(). This mechanism is not used (AFAIR and AFAICanSeeNow). The alternative way is to support your magics within each JIT. (Mikhail does things like that in OPT just from JavaByteCodeTranslator.cpp (see isMagicClass(...)) Thanks! I'll look it. It works for JET, but failed when OPT recompile these method. Does the OPT go different path? If so, how can I override it? Does anyone can help me? how does it fail? did you try it with -Xem:opt? (That's what I tend to always ask about:) Just a guess: OPT expects some profile from JET, but cannot find any. I mean, the overriding succeeds when I use JET only, i.e., java - Dem.properties=jet If I use the default configuration java ..., at the beginning, the overriding is successful because the code is compiled by JET. But later, when the EM invoke OPT to re-compile the hot code, the overriding does not work any longer. It fall back to the original java code. So, where do you think is the best place in OPT for the overriding code? And is there a common path for both JET and OPT? -- Egor Pasko, Intel Managed Runtime Division
Re: [drlvm][jit] How to override jit compilation?
2006/10/30, Alex Astapchuk [EMAIL PROTECTED]: Tonny, Tonny Lau wrote: Hi, I want to override some specific java methods with native fast path implementations. So I try to override them in compile_do_compilation_jit()(vm/vmcore/src/jit/compile.cpp), that is, I add several entries in _stub_override_entries_base[](vm/vmcore/src/util/ia32/base/compile_IA32.cpp), and lookup this table before invoke jit-compile_method_with_params(). It works for JET, but failed when OPT recompile these method. Does the OPT go different path? I suppose it's because OPT inlines the methods of your interest, so they simply do not go through the VM's compilation machinery. If so, how can I override it? Does anyone can help me? Try to turn off inlining in OPT - will it help? You're right. It works for OPT after I disable inline. :) But there is a performance regression when the compiler switch to OPT. I'll continue the investigation. Thanks! -- Thanks, Alex
Re: [drlvm][jit] How to override jit compilation?
Tonny Lau wrote: 2006/10/30, Alex Astapchuk [EMAIL PROTECTED]: Tonny, Tonny Lau wrote: Hi, I want to override some specific java methods with native fast path implementations. So I try to override them in compile_do_compilation_jit()(vm/vmcore/src/jit/compile.cpp), that is, I add several entries in _stub_override_entries_base[](vm/vmcore/src/util/ia32/base/compile_IA32.cpp), and lookup this table before invoke jit-compile_method_with_params(). It works for JET, but failed when OPT recompile these method. Does the OPT go different path? I suppose it's because OPT inlines the methods of your interest, so they simply do not go through the VM's compilation machinery. If so, how can I override it? Does anyone can help me? Try to turn off inlining in OPT - will it help? You're right. It works for OPT after I disable inline. :) But there is a performance regression when the compiler switch to OPT. I'll continue the investigation. Thanks! Well, I don't see much options here rather than do the overriding in the OPT codebase. VM guys may correct me here: As far as I remember, the VM had a special machinery to override the methods [1]. if memory serves, the method entries were handled on class preparation - somewhere at [2]. So the JIT 'saw' them as native and did not try to inline them. Seems very close to the functionality you need. However after a quick look on the latest srcs, it seems the machinery is not used anymore. [1] Have a look at the end of vmcore\src\util\ia32\base\compile_IA32.cpp - it's the table for the methods handles in a special way. [2] vmcore\src\class_support\Prepare.cpp -- Thanks, Alex