1 /* Copyright (C) 2008 The Android Open Source Project 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /* 17 * The class loader will associate with each method a 32-bit info word 18 * (jniArgInfo) to support JNI calls. The high order 4 bits of this word 19 * are the same for all targets, while the lower 28 are used for hints to 20 * allow accelerated JNI bridge transfers. 21 * 22 * jniArgInfo (32-bit int) layout: 23 * 24 * SRRRHHHH HHHHHHHH HHHHHHHH HHHHHHHH 25 * 26 * S - if set, ignore the hints and do things the hard way (scan signature) 27 * R - return-type enumeration 28 * H - target-specific hints (see below for details) 29 * 30 * This function produces IA32-specific hints for the standard 32-bit 386 ABI. 31 * All arguments have 32-bit alignment. Padding is not an issue. 32 * 33 * IA32 ABI JNI hint format 34 * 35 * ZZZZ ZZZZZZZZ AAAAAAAA AAAAAAAA 36 * 37 * Z - reserved, must be 0 38 * A - size of variable argument block in 32-bit words (note - does not 39 * include JNIEnv or clazz) 40 * 41 * For the 386 ABI, valid hints should always be generated. 42 */ 43 44 45 #include "Dalvik.h" 46 #include "libdex/DexClass.h" 47 #include <stdlib.h> 48 #include <stddef.h> 49 #include <sys/stat.h> 50 51 u4 dvmPlatformInvokeHints(const DexProto* proto) { 52 53 const char* sig = dexProtoGetShorty(proto); 54 unsigned int wordCount = 0; 55 char sigByte; 56 57 while (1) { 58 59 /* 60 * Move past return type; dereference sigByte 61 */ 62 63 sigByte = *(++sig); 64 if (sigByte == '\0') { break; } 65 ++wordCount; 66 67 if (sigByte == 'D' || sigByte == 'J') { 68 ++wordCount; 69 } 70 } 71 72 /* 73 * Check for Dex file limitation and return 74 */ 75 76 if (wordCount > 0xFFFF) { return DALVIK_JNI_NO_ARG_INFO; } 77 return wordCount; 78 79 } 80