122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch   /* Copyright (C) 2008 The Android Open Source Project
222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Licensed under the Apache License, Version 2.0 (the "License");
422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * you may not use this file except in compliance with the License.
522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * You may obtain a copy of the License at
622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * http://www.apache.org/licenses/LICENSE-2.0
822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Unless required by applicable law or agreed to in writing, software
1022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * distributed under the License is distributed on an "AS IS" BASIS,
1122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * See the License for the specific language governing permissions and
1322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * limitations under the License.
1422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    */
1522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
1622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch   /*
1722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * The class loader will associate with each method a 32-bit info word
1822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * (jniArgInfo) to support JNI calls.  The high order 4 bits of this word
1922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * are the same for all targets, while the lower 28 are used for hints to
2022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * allow accelerated JNI bridge transfers.
2122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
2222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * jniArgInfo (32-bit int) layout:
2322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
2422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *    SRRRHHHH HHHHHHHH HHHHHHHH HHHHHHHH
2522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
2622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *    S - if set, ignore the hints and do things the hard way (scan signature)
2722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *    R - return-type enumeration
2822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *    H - target-specific hints (see below for details)
2922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
3022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * This function produces IA32-specific hints for the standard 32-bit 386 ABI.
3122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * All arguments have 32-bit alignment.  Padding is not an issue.
3222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
3322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * IA32 ABI JNI hint format
3422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
3522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *       ZZZZ ZZZZZZZZ AAAAAAAA AAAAAAAA
3622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
3722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *   Z - reserved, must be 0
3822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *   A - size of variable argument block in 32-bit words (note - does not
3922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *       include JNIEnv or clazz)
4022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
4122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * For the 386 ABI, valid hints should always be generated.
4222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    */
4322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
4422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
4522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch#include "Dalvik.h"
4622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch#include "libdex/DexClass.h"
4722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch#include <stdlib.h>
4822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch#include <stddef.h>
4922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch#include <sys/stat.h>
5022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
5122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birchu4 dvmPlatformInvokeHints(const DexProto* proto)  {
5222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
5322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birchconst char* sig = dexProtoGetShorty(proto);
5422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birchunsigned int wordCount = 0;
5522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birchchar sigByte;
5622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
5722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch while (1) {
5822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
5922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch   /*
6022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Move past return type; dereference sigByte
6122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    */
6222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
6322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    sigByte = *(++sig);
6422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    if (sigByte == '\0') { break; }
6522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    ++wordCount;
6622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
6722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    if (sigByte == 'D' || sigByte == 'J') {
6822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch      ++wordCount;
6922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    }
7022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch }
7122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
7222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch/*
7322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch * Check for Dex file limitation and return
7422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch */
7522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
7622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch if (wordCount > 0xFFFF) { return DALVIK_JNI_NO_ARG_INFO; }
7722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch return wordCount;
7822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
7922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch}
80