Return-Path: Delivered-To: apmail-incubator-harmony-dev-archive@www.apache.org Received: (qmail 1411 invoked from network); 18 Oct 2006 00:36:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 18 Oct 2006 00:36:43 -0000 Received: (qmail 58995 invoked by uid 500); 18 Oct 2006 00:36:40 -0000 Delivered-To: apmail-incubator-harmony-dev-archive@incubator.apache.org Received: (qmail 58810 invoked by uid 500); 18 Oct 2006 00:36:40 -0000 Mailing-List: contact harmony-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-dev@incubator.apache.org Received: (qmail 58799 invoked by uid 99); 18 Oct 2006 00:36:40 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Oct 2006 17:36:40 -0700 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=DNS_FROM_RFC_ABUSE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of xiaofeng.li@gmail.com designates 66.249.92.172 as permitted sender) Received: from [66.249.92.172] (HELO ug-out-1314.google.com) (66.249.92.172) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Oct 2006 17:36:37 -0700 Received: by ug-out-1314.google.com with SMTP id y2so95852uge for ; Tue, 17 Oct 2006 17:36:16 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=P6YHasrvc39l7VsRd18UGvWC/T0fyUWl8tmyfx0CRIrfkf6EUg7zM49RMvolxaXzpnrjlSpqThZAlLoeimVkUGkp00BIFcCYemk30IbrbfexqI30Lqmk0OplryW37/7CKn6lZzxFprBAd8HZLLnqBVTsIHsvnuRcbvPhdbjdxMQ= Received: by 10.78.150.7 with SMTP id x7mr10249868hud; Tue, 17 Oct 2006 17:36:15 -0700 (PDT) Received: by 10.78.154.18 with HTTP; Tue, 17 Oct 2006 17:36:15 -0700 (PDT) Message-ID: <9623c9a50610171736x39ee6619o68558e4fd39c4564@mail.gmail.com> Date: Wed, 18 Oct 2006 08:36:15 +0800 From: "Xiao-Feng Li" To: harmony-dev@incubator.apache.org Subject: Re: [drlvm] Calling native methods from Java code: implementation details In-Reply-To: <783bf8b0610171212n41d1f47cm37fd77670039c9ec@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=WINDOWS-1252; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <51d555c70610171014gd507b14hce9f2c80b6096c04@mail.gmail.com> <783bf8b0610171212n41d1f47cm37fd77670039c9ec@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hi, I think Pavel and Mikhail's proposals are essentially the same. Pavel's looks like more flexible, but I have a question with the special interface approach: is it possible that sometimes we want to call a library native method in fast way? If possible, shall we require all library classes that have the native method implement the special interface? Or, is it possible for the VM developer to override a library native method with a fast internal replacement that still keeps the semantics? In this situation, this method is not really implemented in the library class. Where will JIT find it? And we probably don't want over-generality to the design of fast native method invocation. We'd better keep them internally to the VM at the moment until we see real need to open this contract interface to external library/application developers. So if you agree with this, the set of non-JNI native methods for JIT to handle are very limited -- they are actually just some JVM internal functions (plus some special cases for speedup). We probably want them more closed than open just like the inlined helpers. Thanks, xiaofeng On 10/18/06, Pavel Afremov wrote: > Mikhail proposal is OK. But I think that following solution is better > > > > 1) The special interface MagicNativeCall should be created. The > interface has only one method CallAddress getCallAddress(String methodNam= e). > All native methods of classes which implement this interface should be > called by JIT via special "magic" way. > > 2) If JIT find call of native method, it tries to find call address > using getCallAddress method. If null is returned by the method, usual cal= l > of JNI method should be processed. In other case magic native call can be > included instead JNI call. Result returned by getCallAddress can and sho= uld > be cashed by JIT for performance reasons. > > 3) I propose for the firs time use fastcall calling convention. In > future new additional method can be added MagicNativeCall interface. It c= an > be named as getCallType for example. If it returns JNI =96 jit should use > stdcall, if FastWay =96 fast call. Also we can add special Magic type of > calling convention. In this type of call one can select Register and stac= k > slot for every parameter and return value. > > > > It can looks like: > > > > ReturnValue methodName(InParameterList ) or > > void methodName(InParameterList, OutParameterList). > > > ReturValue is an void or OutValue, InParameterList is an empty or separa= ted > by comma "," list of the InValue, OutParameterList is an empty or separat= ed > by comma "," list of the OutValue. > > The OutValue can by one of OutRegisterParametr## or OutStackParametr##, > where ## number of register or call in the stack, which are possible on t= he > current platform. > > > The InValue can be one of InRegisterParametr## or InStackParametr##. > > > > Register## and Stack## is the short aliases for InRegisterParametr## and > InStackParametr## correspondently. Result is the short alias for > OutRegisterParametr00 (EAX on ia32). > > > > Generics can be used for type safety. > > > > Thanks. > > Pavel Afremov. > > > On 10/17/06, Rana Dasgupta wrote: > > > > Mikhail, > > All this looks reasonable to me. At least to go ahead. Regarding 2A, > > could the jit cache this information for re-use? > > Alternatively, the JIT can do all this at startup...by going thru the > > contract class of fastpath java methods and querying the component mana= ger > > for the native addresses of the slow counterparts. > > > > Thanks, > > Rana > > > > > > On 10/17/06, Mikhail Fursov wrote: > > > > > > All, > > > Finally we have almost everything finished to post "helper's fast-pat= h > > > inlining" framework into JIRA. > > > > > > The issue is left is how to call native slow-path versions of the fro= m > > > Java > > > code. We already discussed some of the aspects, but there was no > > detailed > > > discussion with a final agreement what API we will use. > > > > > > Let's make a final decision so I can add the code into JIRA. > > > > > > I'm sending my vision of the solution. Correct me or advise another > > > approach. > > > > > > Step 1: How JIT will know if a Java method must be replaced with a > > native > > > helper call. > > > Solution 1.A: Every Java method that must be replaced with native cal= l > > > must > > > be a static method and must have special "Native" runtime method > > > annotation. > > > > > > Step 2: How JIT will get the address of the native method to generate= a > > > direct call? > > > Solution 2.A: Every Java method that must be replaced with native cal= l > > > must > > > have special "Component" annotation. > > > JIT will use this annotation to ask Component Manager to access to th= e > > > specified component by it's name and call "void* getAddress(const cha= r* > > > methodName)" component's method to get the address of a helper. That = is > > > every component that have native calls from Java must provide this > > > interface. > > > > > > Step 3: How JIT will know which calling convention to use? > > > Solution 3.A: Use method's annotation again. > > > > > > > > > These were all of the problems with native calls. Now we need to agre= e > > if > > > the solution proposed is OK or find another one. > > > Please note, that this is just the first implementation. We can exten= d > > it > > > with more features in the future. > > > > > > > > > > > > -- > > > Mikhail Fursov > > > > > > > > > > > > --------------------------------------------------------------------- Terms of use : http://incubator.apache.org/harmony/mailing.html To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org For additional commands, e-mail: harmony-dev-help@incubator.apache.org