harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r446488 [2/3] - in /incubator/harmony/enhanced/classlib/trunk/modules/instrument: ./ .settings/ META-INF/ make/ src/main/java/java/lang/instrument/ src/main/java/org/apache/harmony/instrument/internal/ src/main/native/instrument/shared/ src...
Date Fri, 15 Sep 2006 03:00:02 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/org/apache/harmony/instrument/internal/InstrumentationImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/org/apache/harmony/instrument/internal/InstrumentationImpl.java?view=diff&rev=446488&r1=446487&r2=446488
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/org/apache/harmony/instrument/internal/InstrumentationImpl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/org/apache/harmony/instrument/internal/InstrumentationImpl.java Thu Sep 14 20:00:01 2006
@@ -1,219 +1,219 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.instrument.internal;
-
-import java.lang.instrument.ClassDefinition;
-import java.lang.instrument.ClassFileTransformer;
-import java.lang.instrument.Instrumentation;
-import java.lang.instrument.UnmodifiableClassException;
-import java.lang.reflect.Method;
-import java.security.ProtectionDomain;
-
-import org.apache.harmony.instrument.internal.nls.Messages;
-
-/**
- * Default implementation of Instrumentation
- */
-public class InstrumentationImpl implements Instrumentation {
-    /*
-     * ----------------------------------------------------------------------------
-     * Consts
-     * ----------------------------------------------------------------------------
-     */
-
-    private static final Class[] PREMAIN_SIGNATURE = new Class[] {
-            String.class, Instrumentation.class };
-
-    /*
-     * ----------------------------------------------------------------------------
-     * Variables
-     * ----------------------------------------------------------------------------
-     */
-    private ClassFileTransformer[] transformers = new ClassFileTransformer[0];
-
-    private boolean isRedefineClassesSupported;
-
-    /*
-     * ----------------------------------------------------------------------------
-     * Constructor
-     * ----------------------------------------------------------------------------
-     */
-    /**
-     * Constructs a new instance.
-     * 
-     * @param isRedefineClassesSupported
-     */
-    public InstrumentationImpl(boolean isRedefineClassesSupported) {
-        this.isRedefineClassesSupported = isRedefineClassesSupported;
-    }
-
-    /*
-     * ----------------------------------------------------------------------------
-     * Methods implemented from Instrumentation
-     * ----------------------------------------------------------------------------
-     */
-    /*
-     * (non-Javadoc)
-     * 
-     * @see java.lang.instrument.Instrumentation#addTransformer(java.lang.instrument.ClassFileTransformer)
-     */
-    public void addTransformer(ClassFileTransformer transformer) {
-        if (null == transformer) {
-            throw new NullPointerException();
-        }
-        int length = transformers.length;
-        ClassFileTransformer[] temp = new ClassFileTransformer[length + 1];
-        System.arraycopy(transformers, 0, temp, 0, length);
-        temp[length] = transformer;
-        transformers = temp;
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see java.lang.instrument.Instrumentation#redefineClasses(java.lang.instrument.ClassDefinition[])
-     */
-    public void redefineClasses(ClassDefinition[] definitions)
-            throws ClassNotFoundException, UnmodifiableClassException {
-        if (!isRedefineClassesSupported) {
-            throw new UnsupportedOperationException(Messages.getString("instrument.3")); //$NON-NLS-1$
-        }
-        for (int i = 0; i < definitions.length; i++) {
-            if (null == definitions[i]) {
-                throw new NullPointerException();
-            }
-        }
-        redefineClasses_native(definitions);
-    }
-
-    private native void redefineClasses_native(ClassDefinition[] definitions);
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see java.lang.instrument.Instrumentation#removeTransformer(java.lang.instrument.ClassFileTransformer)
-     */
-    public boolean removeTransformer(ClassFileTransformer transformer) {
-        if (null == transformer) {
-            throw new NullPointerException();
-        }
-        int i = 0;
-        int length = transformers.length;
-        for (i = length-1; i >= 0 && transformers[i] != transformer; i--)
-            ;
-        if (i == -1) {
-            return false;
-        }
-        ClassFileTransformer[] temp = new ClassFileTransformer[length - 1];
-        if (i > 0) {
-            System.arraycopy(transformers, 0, temp, 0, i);
-        }
-        if (i < length - 1) {
-            System.arraycopy(transformers, i + 1, temp, i, length - i - 1);
-        }
-        transformers = temp;
-        return true;
-    }
-
-    public void clear() {
-        transformers = new ClassFileTransformer[0];
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see java.lang.instrument.Instrumentation#getAllLoadedClasses()
-     */
-    public native Class[] getAllLoadedClasses();
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see java.lang.instrument.Instrumentation#getInitiatedClasses(java.lang.ClassLoader)
-     */
-    public native Class[] getInitiatedClasses(ClassLoader loader);
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see java.lang.instrument.Instrumentation#getObjectSize(java.lang.Object)
-     */
-    public long getObjectSize(Object objectToSize) {
-        if (null == objectToSize) {
-            throw new NullPointerException();
-        }
-        return getObjectSize_native(objectToSize);
-    }
-
-    private native long getObjectSize_native(Object objectToSize);
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see java.lang.instrument.Instrumentation#isRedefineClassesSupported()
-     */
-    public boolean isRedefineClassesSupported() {
-        return isRedefineClassesSupported;
-    }
-
-    /*
-     * ----------------------------------------------------------------------------
-     * Callback methods for native JVMTI agent
-     * ----------------------------------------------------------------------------
-     */
-    /*
-     * ClassFileLoadHook event handler method
-     */
-    private byte[] transform(ClassLoader loader, byte[] classNameBytes,
-            Class<?> classBeingRedefined, ProtectionDomain protectionDomain,
-            byte[] classfileBuffer) {
-        byte[] source = classfileBuffer;
-        byte[] result = null;
-        byte[] trans = null;
-        String className = new String(classNameBytes);
-        for (ClassFileTransformer t : transformers) {
-            try {
-                trans = t.transform(loader, className, classBeingRedefined,
-                        protectionDomain, source);
-                if (null != trans && 0 != trans.length) {
-                    result = trans;
-                    source = trans;
-                }
-            } catch (Exception e) {
-                // nothing to do, just continue~
-            }
-        }
-        return result;
-    }
-
-    /*
-     * callback method to execute javaagents' premain method
-     */
-    private void executePremain(byte[] className, byte[] options) {
-        try {
-            ClassLoader loader = ClassLoader.getSystemClassLoader();
-            Class c = loader.loadClass(new String(className));
-            Method method = c.getMethod("premain", PREMAIN_SIGNATURE); //$NON-NLS-1$
-            method.invoke(null, new Object[] {
-                    null == options ? null : new String(options), this });
-        } catch (Exception e) {
-            e.printStackTrace();
-            System.err
-                    .println(Messages.getString("instrument.4")); //$NON-NLS-1$
-            System.exit(1);
-        }
-    }
-}
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.instrument.internal;
+
+import java.lang.instrument.ClassDefinition;
+import java.lang.instrument.ClassFileTransformer;
+import java.lang.instrument.Instrumentation;
+import java.lang.instrument.UnmodifiableClassException;
+import java.lang.reflect.Method;
+import java.security.ProtectionDomain;
+
+import org.apache.harmony.instrument.internal.nls.Messages;
+
+/**
+ * Default implementation of Instrumentation
+ */
+public class InstrumentationImpl implements Instrumentation {
+    /*
+     * ----------------------------------------------------------------------------
+     * Consts
+     * ----------------------------------------------------------------------------
+     */
+
+    private static final Class[] PREMAIN_SIGNATURE = new Class[] {
+            String.class, Instrumentation.class };
+
+    /*
+     * ----------------------------------------------------------------------------
+     * Variables
+     * ----------------------------------------------------------------------------
+     */
+    private ClassFileTransformer[] transformers = new ClassFileTransformer[0];
+
+    private boolean isRedefineClassesSupported;
+
+    /*
+     * ----------------------------------------------------------------------------
+     * Constructor
+     * ----------------------------------------------------------------------------
+     */
+    /**
+     * Constructs a new instance.
+     * 
+     * @param isRedefineClassesSupported
+     */
+    public InstrumentationImpl(boolean isRedefineClassesSupported) {
+        this.isRedefineClassesSupported = isRedefineClassesSupported;
+    }
+
+    /*
+     * ----------------------------------------------------------------------------
+     * Methods implemented from Instrumentation
+     * ----------------------------------------------------------------------------
+     */
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.lang.instrument.Instrumentation#addTransformer(java.lang.instrument.ClassFileTransformer)
+     */
+    public void addTransformer(ClassFileTransformer transformer) {
+        if (null == transformer) {
+            throw new NullPointerException();
+        }
+        int length = transformers.length;
+        ClassFileTransformer[] temp = new ClassFileTransformer[length + 1];
+        System.arraycopy(transformers, 0, temp, 0, length);
+        temp[length] = transformer;
+        transformers = temp;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.lang.instrument.Instrumentation#redefineClasses(java.lang.instrument.ClassDefinition[])
+     */
+    public void redefineClasses(ClassDefinition[] definitions)
+            throws ClassNotFoundException, UnmodifiableClassException {
+        if (!isRedefineClassesSupported) {
+            throw new UnsupportedOperationException(Messages.getString("instrument.3")); //$NON-NLS-1$
+        }
+        for (int i = 0; i < definitions.length; i++) {
+            if (null == definitions[i]) {
+                throw new NullPointerException();
+            }
+        }
+        redefineClasses_native(definitions);
+    }
+
+    private native void redefineClasses_native(ClassDefinition[] definitions);
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.lang.instrument.Instrumentation#removeTransformer(java.lang.instrument.ClassFileTransformer)
+     */
+    public boolean removeTransformer(ClassFileTransformer transformer) {
+        if (null == transformer) {
+            throw new NullPointerException();
+        }
+        int i = 0;
+        int length = transformers.length;
+        for (i = length-1; i >= 0 && transformers[i] != transformer; i--)
+            ;
+        if (i == -1) {
+            return false;
+        }
+        ClassFileTransformer[] temp = new ClassFileTransformer[length - 1];
+        if (i > 0) {
+            System.arraycopy(transformers, 0, temp, 0, i);
+        }
+        if (i < length - 1) {
+            System.arraycopy(transformers, i + 1, temp, i, length - i - 1);
+        }
+        transformers = temp;
+        return true;
+    }
+
+    public void clear() {
+        transformers = new ClassFileTransformer[0];
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.lang.instrument.Instrumentation#getAllLoadedClasses()
+     */
+    public native Class[] getAllLoadedClasses();
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.lang.instrument.Instrumentation#getInitiatedClasses(java.lang.ClassLoader)
+     */
+    public native Class[] getInitiatedClasses(ClassLoader loader);
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.lang.instrument.Instrumentation#getObjectSize(java.lang.Object)
+     */
+    public long getObjectSize(Object objectToSize) {
+        if (null == objectToSize) {
+            throw new NullPointerException();
+        }
+        return getObjectSize_native(objectToSize);
+    }
+
+    private native long getObjectSize_native(Object objectToSize);
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.lang.instrument.Instrumentation#isRedefineClassesSupported()
+     */
+    public boolean isRedefineClassesSupported() {
+        return isRedefineClassesSupported;
+    }
+
+    /*
+     * ----------------------------------------------------------------------------
+     * Callback methods for native JVMTI agent
+     * ----------------------------------------------------------------------------
+     */
+    /*
+     * ClassFileLoadHook event handler method
+     */
+    private byte[] transform(ClassLoader loader, byte[] classNameBytes,
+            Class<?> classBeingRedefined, ProtectionDomain protectionDomain,
+            byte[] classfileBuffer) {
+        byte[] source = classfileBuffer;
+        byte[] result = null;
+        byte[] trans = null;
+        String className = new String(classNameBytes);
+        for (ClassFileTransformer t : transformers) {
+            try {
+                trans = t.transform(loader, className, classBeingRedefined,
+                        protectionDomain, source);
+                if (null != trans && 0 != trans.length) {
+                    result = trans;
+                    source = trans;
+                }
+            } catch (Exception e) {
+                // nothing to do, just continue~
+            }
+        }
+        return result;
+    }
+
+    /*
+     * callback method to execute javaagents' premain method
+     */
+    private void executePremain(byte[] className, byte[] options) {
+        try {
+            ClassLoader loader = ClassLoader.getSystemClassLoader();
+            Class c = loader.loadClass(new String(className));
+            Method method = c.getMethod("premain", PREMAIN_SIGNATURE); //$NON-NLS-1$
+            method.invoke(null, new Object[] {
+                    null == options ? null : new String(options), this });
+        } catch (Exception e) {
+            e.printStackTrace();
+            System.err
+                    .println(Messages.getString("instrument.4")); //$NON-NLS-1$
+            System.exit(1);
+        }
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/java/org/apache/harmony/instrument/internal/InstrumentationImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/inst_agt.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/inst_agt.c?view=diff&rev=446488&r1=446487&r2=446488
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/inst_agt.c (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/inst_agt.c Thu Sep 14 20:00:01 2006
@@ -1,384 +1,384 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define USING_VMI
-
-#include "instrument.h"
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <zipsup.h>
-#include <jni.h>
-#include <vmi.h>
-
-/*
- * This file implements a JVMTI agent to init Instrument instance, and handle class define/redefine events
- */
-
-AgentList *tail = &list;
-int gsupport_redefine = 0;
-static JNIEnv *jnienv;
-
-//call back function for ClassLoad event
-void JNICALL callbackClassFileLoadHook(jvmtiEnv *jvmti_env,
-	JNIEnv* jni_env,
-	jclass class_being_redefined,
-	jobject loader,
-	const char* name,
-	jobject protection_domain,
-	jint class_data_len,
-	const unsigned char* class_data,
-	jint* new_class_data_len,
-	unsigned char** new_class_data){
-
-	jclass inst_class = *(gdata->inst_class);
-	jbyteArray jnew_bytes = NULL;
-	jbyteArray jold_bytes = (*jni_env)->NewByteArray(jni_env, class_data_len);
-	jmethodID transform_method = *(gdata->transform_method);
-	int name_len = strlen(name);
-	jbyteArray jname_bytes = (*jni_env)->NewByteArray(jni_env, name_len);
-	
-	//construct java byteArray for old class data and class name
-	(*jni_env)->SetByteArrayRegion(jni_env, jold_bytes, 0, class_data_len, (unsigned char *)class_data);
-	(*jni_env)->SetByteArrayRegion(jni_env, jname_bytes, 0, name_len, (char *)name);
-	
-	//invoke transform method
-	jnew_bytes = (jbyteArray)(*jni_env)->CallObjectMethod(jni_env, *(gdata->inst), transform_method, loader, jname_bytes, class_being_redefined, protection_domain, jold_bytes);	
-
-	//get transform result to native char array
-	if(0 != jnew_bytes){
-		*new_class_data_len = (*jni_env)->GetArrayLength(jni_env, jnew_bytes);
-		(*jvmti_env)->Allocate(jvmti_env, *new_class_data_len, new_class_data);		
-		*new_class_data = (*jni_env)->GetPrimitiveArrayCritical(jni_env, jnew_bytes, JNI_FALSE);
-		(*jni_env)->ReleasePrimitiveArrayCritical(jni_env, jnew_bytes, *new_class_data, 0);
-	}
-	return;
-}
-
-//call back function for VM init event
-void JNICALL callbackVMInit(jvmtiEnv *jvmti, JNIEnv *env, jthread thread){
-	jmethodID constructor;
-	static jmethodID transform_method;
-	static jmethodID premain_method;
-	static jobject inst_obj;
-	static jclass inst_class;
-	jvmtiError err;
-	AgentList *elem;
-	
-	PORT_ACCESS_FROM_ENV (env);	
-	inst_class = (*env)->FindClass(env, "org/apache/harmony/instrument/internal/InstrumentationImpl");
-	if(NULL == inst_class){		
-		(*env)->FatalError(env,"class cannot find: org/apache/harmony/instrument/internal/InstrumentationImpl");
-		return;	
-	}
-	inst_class = (jclass)(*env)->NewGlobalRef(env, inst_class);
-	gdata->inst_class = &inst_class;
-
-	constructor = (*env)->GetMethodID(env, inst_class,"<init>", "(Z)V");
-	if(NULL == constructor){
-		(*env)->FatalError(env,"constructor cannot be found.");				
-		return;
-	}
-	
-	inst_obj = (*env)->NewObject(env, inst_class, constructor, gsupport_redefine?JNI_TRUE:JNI_FALSE);
-	if(NULL == inst_obj){
-		(*env)->FatalError(env,"object cannot be inited.");				
-		return;		
-	}
-	
-	inst_obj = (*env)->NewGlobalRef(env, inst_obj);
-	gdata->inst = &inst_obj;
-
-	transform_method = (*env)->GetMethodID(env, inst_class, "transform", "(Ljava/lang/ClassLoader;[BLjava/lang/Class;Ljava/security/ProtectionDomain;[B)[B");
-	if(NULL == transform_method){
-		(*env)->FatalError(env,"transform method cannot find.");
-		return;
-	}
-	gdata->transform_method = &transform_method;
-
-	premain_method = (*env)->GetMethodID(env, inst_class, "executePremain", "([B[B)V");
-	if(NULL == premain_method){
-		(*env)->FatalError(env,"executePremain method cannot find.");
-		return;
-	}
-	gdata->premain_method = &premain_method;		
-	err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL);	
-	check_jvmti_error(env, err, "Cannot set JVMTI ClassFileLoadHook event notification mode.");
-	
-	//parse command options and run premain class here	
-	if(tail == &list){
-		return;
-	}
-	for(elem = list.next; elem != NULL; elem = list.next){
-		char *agent_options = elem->option;	
-		char *class_name = elem->class_name;
-		jbyteArray joptions=NULL, jclass_name;
-		if(class_name){
-			jclass_name = (*env)->NewByteArray(env, strlen(class_name));
-			(*env)->SetByteArrayRegion(env, jclass_name, 0, strlen(class_name), class_name);
-		}else{
-			goto DEALLOCATE;
-		}
-		if(agent_options){
-			joptions = (*env)->NewByteArray(env, strlen(agent_options));
-			(*env)->SetByteArrayRegion(env, joptions, 0, strlen(agent_options), agent_options);
-		}
-		
-		(*env)->CallObjectMethod(env, *(gdata->inst), *(gdata->premain_method), jclass_name, joptions);
-DEALLOCATE:
-		list.next = elem->next;
-		hymem_free_memory(elem->class_name);
-		hymem_free_memory(elem->option);
-		hymem_free_memory(elem);
-	}	
-	tail = &list;	
-}
-
-char* Read_Manifest(JavaVM *vm, JNIEnv *env,const char *jar_name){
-	I_32 retval;
-	HyZipFile zipFile;
-	HyZipEntry zipEntry;
-	char *result;
-	int size = 0;
-	char errorMessage[1024];
-
-	/* Reach for the VM interface */	
-	VMI_ACCESS_FROM_JAVAVM(vm);
-	PORT_ACCESS_FROM_JAVAVM(vm);
-
-	/* open zip file */
-	retval = zip_openZipFile(privatePortLibrary, (char *)jar_name, &zipFile, NULL);
-	if(retval){
-		sprintf(errorMessage,"failed to open file:%s, %d\n", jar_name, retval);
-		(*env)->FatalError(env, errorMessage);
-		return NULL;
-	}
-
-	/* get manifest entry */
-	zip_initZipEntry(privatePortLibrary, &zipEntry);
-	retval = zip_getZipEntry(privatePortLibrary, &zipFile, &zipEntry, "META-INF/MANIFEST.MF", TRUE);
-	if (retval) {
-		zip_freeZipEntry(PORTLIB, &zipEntry);
-		sprintf(errorMessage,"failed to get entry: %d\n", retval);
-		(*env)->FatalError(env, errorMessage);
-		return NULL;
-	}
-	
-	/* read bytes */
-	size = zipEntry.uncompressedSize;
-	result = (char *)hymem_allocate_memory(size*sizeof(char));
-	retval = zip_getZipEntryData(privatePortLibrary, &zipFile, &zipEntry, result, size);
-	if(retval){
-		zip_freeZipEntry(PORTLIB, &zipEntry);
-		sprintf(errorMessage,"failed to get bytes from zip entry, %d\n", zipEntry.extraFieldLength);
-		(*env)->FatalError(env, errorMessage);
-		return NULL;
-	}
-
-	/* free resource */
-	zip_freeZipEntry(privatePortLibrary, &zipEntry);
-	retval = zip_closeZipFile(privatePortLibrary, &zipFile);
-	if (retval) {
-		sprintf(errorMessage,"failed to close zip file: %s, %d\n", jar_name, retval);
-		(*env)->FatalError(env, errorMessage);
-		return NULL;
-	}
-	return result;
-}
-
-char* read_attribute(JavaVM *vm, char *manifest,char *lwrmanifest, const char * target){
-	char *pos;
-	char *end;
-	char *value;
-	int length;
-    PORT_ACCESS_FROM_JAVAVM(vm);
-    
-    if(NULL == strstr(lwrmanifest,target)){
-		return NULL;
-	}
-    
-    pos = manifest+ (strstr(lwrmanifest,target) - lwrmanifest);
-	pos += strlen(target)+2;//": "
-	end = strchr(pos, '\n');	
-	if(NULL == end){
-		end = manifest + strlen(manifest);
-	}
-	/* in windows, has '\r\n' in the end of line, omit '\r' */
-	if (*(end - 1) == '\r'){
-		end--;
-	}
-	length = end - pos;
-	
-	value = (char *)hymem_allocate_memory(sizeof(char)*(length+1));
-	strncpy(value, pos, length);
-	*(value+length) = '\0';
-	return value;
-}
-
-char* strlower(char * str){
-     char *temp = str;
-     while(*temp = tolower(*temp))
-         temp++;
-     return str;
-}
-
-int str2bol(char *str){	
-	return 0 == strcmp("true", strlower(str));
-}
-
-jint Parse_Options(JavaVM *vm, JNIEnv *env, jvmtiEnv *jvmti,  const char *agent){
-	PORT_ACCESS_FROM_JAVAVM(vm);
-	VMI_ACCESS_FROM_JAVAVM(vm);
-	
-	AgentList *new_elem = (AgentList *)hymem_allocate_memory(sizeof(AgentList));
-	char *agent_cpy = (char *)hymem_allocate_memory(sizeof(char)*(strlen(agent)+1));
-	char *jar_name, *manifest;
-	char *options = NULL;
-	char *class_name, *bootclasspath, *str_support_redefine;	
-	char *bootclasspath_item;
-	char *classpath;
-	char *classpath_cpy;
-	int support_redefine = 0;
-	char *pos;
-	char *lwrmanifest;
-	
-	strcpy(agent_cpy, agent);
-	//parse jar name and options
-	pos = strchr(agent_cpy, '=');
-	if(pos>0){
-		*pos++ = 0;
-		options = (char *)hymem_allocate_memory(sizeof(char) * (strlen(pos)+1));
-		strcpy(options, pos);
-		hymem_free_memory(pos);
-	}
-	jar_name =agent_cpy;
-
-	//read jar files, find manifest entry and read bytes
-	//read attributes(premain class, support redefine, bootclasspath)
-	manifest = Read_Manifest(vm,env, jar_name);	
-	lwrmanifest = (char *)hymem_allocate_memory(sizeof(char) * (strlen(manifest)+1));
-	strcpy(lwrmanifest,manifest);
-	strlower(lwrmanifest);
-	
-	//jar itself added to bootclasspath
-	check_jvmti_error(env, (*jvmti)->GetSystemProperty(jvmti,"java.class.path",&classpath),"Failed to get classpath.");
-	classpath_cpy = (char *)hymem_allocate_memory((sizeof(char)*(strlen(classpath)+strlen(jar_name)+2)));
-	strcpy(classpath_cpy,classpath);
-	strcat(classpath_cpy,";");
-	strcat(classpath_cpy,jar_name);
-	check_jvmti_error(env, (*jvmti)->SetSystemProperty(jvmti, "java.class.path",classpath_cpy),"Failed to set classpath.");
-	hymem_free_memory(classpath_cpy);
-	hymem_free_memory(jar_name);	
-
-	//save options, save class name, add to agent list
-	class_name = read_attribute(vm, manifest, lwrmanifest,"premain-class");
-	if(NULL == class_name){
-		hymem_free_memory(lwrmanifest);
-		hymem_free_memory(manifest);
-		(*env)->FatalError(env,"Cannot find Premain-Class attribute.");
-	}
-	new_elem->option = options;
-	new_elem->class_name = class_name;
-	new_elem->next = NULL;
-	tail->next = new_elem;
-	tail = new_elem;
-
-	//calculate support redefine
-	str_support_redefine = read_attribute(vm, manifest, lwrmanifest,"can-redefine-classes");
-	if(NULL != str_support_redefine){
-		support_redefine = str2bol(str_support_redefine);	
-		gsupport_redefine |= support_redefine;
-		hymem_free_memory(str_support_redefine);
-	}
-	
-	//add bootclasspath
-	
-	bootclasspath = read_attribute(vm, manifest, lwrmanifest,"boot-class-path");
-	if(NULL != bootclasspath){
-		bootclasspath_item = strtok(bootclasspath, " ");
-		while(NULL != bootclasspath_item){			
-			check_jvmti_error(env, (*jvmti)->AddToBootstrapClassLoaderSearch(jvmti, bootclasspath_item),"Failed to add bootstrap classpath.");			
-			bootclasspath_item = strtok(NULL, " ");
-		}
-		hymem_free_memory(bootclasspath);
-	}	
-	hymem_free_memory(lwrmanifest);
-	hymem_free_memory(manifest);
-	return 0;
-}
-
-JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved){	
-	PORT_ACCESS_FROM_JAVAVM(vm);
-	VMI_ACCESS_FROM_JAVAVM(vm);
-	jint err = (*vm)->GetEnv(vm, (void **)&jnienv, JNI_VERSION_1_2);
-	if(JNI_OK != err){
-		return err;
-	}
-	
-	if(!gdata){		
-		jvmtiCapabilities capabilities;		
-		jvmtiError err;
-		jvmtiEventCallbacks callbacks;
-		JNIEnv *env = NULL;
-		static jvmtiEnv *jvmti;
-
-		gdata = hymem_allocate_memory(sizeof(AgentData));
-		
-		//get jvmti environment
-		err = (*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_0);
-		if(JNI_OK != err){
-			return err;
-		}		
-		gdata->jvmti = jvmti;
-		
-		//set prerequisite capabilities for classfileloadhook, redefine, and VMInit event
-		memset(&capabilities, 0, sizeof(capabilities));
-		capabilities.can_generate_all_class_hook_events=1;
-		capabilities.can_redefine_classes = 1;
-		//FIXME VM doesnot support the capbility right now.
-		//capabilities.can_redefine_any_class = 1;
-		err = (*jvmti)->AddCapabilities(jvmti, &capabilities);
-		check_jvmti_error(env, err, "Cannot add JVMTI capabilities.");
-
-		//set events callback function
-		(void)memset(&callbacks, 0, sizeof(callbacks));
-		callbacks.ClassFileLoadHook = &callbackClassFileLoadHook;
-		callbacks.VMInit = &callbackVMInit;
-		err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(jvmtiEventCallbacks));
-		check_jvmti_error(env, err, "Cannot set JVMTI event callback functions.");
-
-		//enable classfileloadhook event
-		err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL);
-		check_jvmti_error(env, err, "Cannot set JVMTI VMInit event notification mode.");
-	}		
-	
-	return Parse_Options(vm,jnienv, gdata->jvmti,options);	
-}
-
-JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm){	
-	PORT_ACCESS_FROM_JAVAVM(vm);
-	VMI_ACCESS_FROM_JAVAVM(vm);
-	//free the resource here	
-	if(gdata){
-		jvmtiEnv *jvmti = gdata->jvmti;
-		jvmtiError err = (*jvmti)->DisposeEnvironment(jvmti);
-		if(err != JVMTI_ERROR_NONE)	{
-		   (*jnienv)->FatalError(jnienv,"Cannot dispose JVMTI environment.");		   
-		}		
-		hymem_free_memory(gdata);
-		gdata = NULL;
-	}
-	return;
-}
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define USING_VMI
+
+#include "instrument.h"
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <zipsup.h>
+#include <jni.h>
+#include <vmi.h>
+
+/*
+ * This file implements a JVMTI agent to init Instrument instance, and handle class define/redefine events
+ */
+
+AgentList *tail = &list;
+int gsupport_redefine = 0;
+static JNIEnv *jnienv;
+
+//call back function for ClassLoad event
+void JNICALL callbackClassFileLoadHook(jvmtiEnv *jvmti_env,
+	JNIEnv* jni_env,
+	jclass class_being_redefined,
+	jobject loader,
+	const char* name,
+	jobject protection_domain,
+	jint class_data_len,
+	const unsigned char* class_data,
+	jint* new_class_data_len,
+	unsigned char** new_class_data){
+
+	jclass inst_class = *(gdata->inst_class);
+	jbyteArray jnew_bytes = NULL;
+	jbyteArray jold_bytes = (*jni_env)->NewByteArray(jni_env, class_data_len);
+	jmethodID transform_method = *(gdata->transform_method);
+	int name_len = strlen(name);
+	jbyteArray jname_bytes = (*jni_env)->NewByteArray(jni_env, name_len);
+	
+	//construct java byteArray for old class data and class name
+	(*jni_env)->SetByteArrayRegion(jni_env, jold_bytes, 0, class_data_len, (unsigned char *)class_data);
+	(*jni_env)->SetByteArrayRegion(jni_env, jname_bytes, 0, name_len, (char *)name);
+	
+	//invoke transform method
+	jnew_bytes = (jbyteArray)(*jni_env)->CallObjectMethod(jni_env, *(gdata->inst), transform_method, loader, jname_bytes, class_being_redefined, protection_domain, jold_bytes);	
+
+	//get transform result to native char array
+	if(0 != jnew_bytes){
+		*new_class_data_len = (*jni_env)->GetArrayLength(jni_env, jnew_bytes);
+		(*jvmti_env)->Allocate(jvmti_env, *new_class_data_len, new_class_data);		
+		*new_class_data = (*jni_env)->GetPrimitiveArrayCritical(jni_env, jnew_bytes, JNI_FALSE);
+		(*jni_env)->ReleasePrimitiveArrayCritical(jni_env, jnew_bytes, *new_class_data, 0);
+	}
+	return;
+}
+
+//call back function for VM init event
+void JNICALL callbackVMInit(jvmtiEnv *jvmti, JNIEnv *env, jthread thread){
+	jmethodID constructor;
+	static jmethodID transform_method;
+	static jmethodID premain_method;
+	static jobject inst_obj;
+	static jclass inst_class;
+	jvmtiError err;
+	AgentList *elem;
+	
+	PORT_ACCESS_FROM_ENV (env);	
+	inst_class = (*env)->FindClass(env, "org/apache/harmony/instrument/internal/InstrumentationImpl");
+	if(NULL == inst_class){		
+		(*env)->FatalError(env,"class cannot find: org/apache/harmony/instrument/internal/InstrumentationImpl");
+		return;	
+	}
+	inst_class = (jclass)(*env)->NewGlobalRef(env, inst_class);
+	gdata->inst_class = &inst_class;
+
+	constructor = (*env)->GetMethodID(env, inst_class,"<init>", "(Z)V");
+	if(NULL == constructor){
+		(*env)->FatalError(env,"constructor cannot be found.");				
+		return;
+	}
+	
+	inst_obj = (*env)->NewObject(env, inst_class, constructor, gsupport_redefine?JNI_TRUE:JNI_FALSE);
+	if(NULL == inst_obj){
+		(*env)->FatalError(env,"object cannot be inited.");				
+		return;		
+	}
+	
+	inst_obj = (*env)->NewGlobalRef(env, inst_obj);
+	gdata->inst = &inst_obj;
+
+	transform_method = (*env)->GetMethodID(env, inst_class, "transform", "(Ljava/lang/ClassLoader;[BLjava/lang/Class;Ljava/security/ProtectionDomain;[B)[B");
+	if(NULL == transform_method){
+		(*env)->FatalError(env,"transform method cannot find.");
+		return;
+	}
+	gdata->transform_method = &transform_method;
+
+	premain_method = (*env)->GetMethodID(env, inst_class, "executePremain", "([B[B)V");
+	if(NULL == premain_method){
+		(*env)->FatalError(env,"executePremain method cannot find.");
+		return;
+	}
+	gdata->premain_method = &premain_method;		
+	err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL);	
+	check_jvmti_error(env, err, "Cannot set JVMTI ClassFileLoadHook event notification mode.");
+	
+	//parse command options and run premain class here	
+	if(tail == &list){
+		return;
+	}
+	for(elem = list.next; elem != NULL; elem = list.next){
+		char *agent_options = elem->option;	
+		char *class_name = elem->class_name;
+		jbyteArray joptions=NULL, jclass_name;
+		if(class_name){
+			jclass_name = (*env)->NewByteArray(env, strlen(class_name));
+			(*env)->SetByteArrayRegion(env, jclass_name, 0, strlen(class_name), class_name);
+		}else{
+			goto DEALLOCATE;
+		}
+		if(agent_options){
+			joptions = (*env)->NewByteArray(env, strlen(agent_options));
+			(*env)->SetByteArrayRegion(env, joptions, 0, strlen(agent_options), agent_options);
+		}
+		
+		(*env)->CallObjectMethod(env, *(gdata->inst), *(gdata->premain_method), jclass_name, joptions);
+DEALLOCATE:
+		list.next = elem->next;
+		hymem_free_memory(elem->class_name);
+		hymem_free_memory(elem->option);
+		hymem_free_memory(elem);
+	}	
+	tail = &list;	
+}
+
+char* Read_Manifest(JavaVM *vm, JNIEnv *env,const char *jar_name){
+	I_32 retval;
+	HyZipFile zipFile;
+	HyZipEntry zipEntry;
+	char *result;
+	int size = 0;
+	char errorMessage[1024];
+
+	/* Reach for the VM interface */	
+	VMI_ACCESS_FROM_JAVAVM(vm);
+	PORT_ACCESS_FROM_JAVAVM(vm);
+
+	/* open zip file */
+	retval = zip_openZipFile(privatePortLibrary, (char *)jar_name, &zipFile, NULL);
+	if(retval){
+		sprintf(errorMessage,"failed to open file:%s, %d\n", jar_name, retval);
+		(*env)->FatalError(env, errorMessage);
+		return NULL;
+	}
+
+	/* get manifest entry */
+	zip_initZipEntry(privatePortLibrary, &zipEntry);
+	retval = zip_getZipEntry(privatePortLibrary, &zipFile, &zipEntry, "META-INF/MANIFEST.MF", TRUE);
+	if (retval) {
+		zip_freeZipEntry(PORTLIB, &zipEntry);
+		sprintf(errorMessage,"failed to get entry: %d\n", retval);
+		(*env)->FatalError(env, errorMessage);
+		return NULL;
+	}
+	
+	/* read bytes */
+	size = zipEntry.uncompressedSize;
+	result = (char *)hymem_allocate_memory(size*sizeof(char));
+	retval = zip_getZipEntryData(privatePortLibrary, &zipFile, &zipEntry, result, size);
+	if(retval){
+		zip_freeZipEntry(PORTLIB, &zipEntry);
+		sprintf(errorMessage,"failed to get bytes from zip entry, %d\n", zipEntry.extraFieldLength);
+		(*env)->FatalError(env, errorMessage);
+		return NULL;
+	}
+
+	/* free resource */
+	zip_freeZipEntry(privatePortLibrary, &zipEntry);
+	retval = zip_closeZipFile(privatePortLibrary, &zipFile);
+	if (retval) {
+		sprintf(errorMessage,"failed to close zip file: %s, %d\n", jar_name, retval);
+		(*env)->FatalError(env, errorMessage);
+		return NULL;
+	}
+	return result;
+}
+
+char* read_attribute(JavaVM *vm, char *manifest,char *lwrmanifest, const char * target){
+	char *pos;
+	char *end;
+	char *value;
+	int length;
+    PORT_ACCESS_FROM_JAVAVM(vm);
+    
+    if(NULL == strstr(lwrmanifest,target)){
+		return NULL;
+	}
+    
+    pos = manifest+ (strstr(lwrmanifest,target) - lwrmanifest);
+	pos += strlen(target)+2;//": "
+	end = strchr(pos, '\n');	
+	if(NULL == end){
+		end = manifest + strlen(manifest);
+	}
+	/* in windows, has '\r\n' in the end of line, omit '\r' */
+	if (*(end - 1) == '\r'){
+		end--;
+	}
+	length = end - pos;
+	
+	value = (char *)hymem_allocate_memory(sizeof(char)*(length+1));
+	strncpy(value, pos, length);
+	*(value+length) = '\0';
+	return value;
+}
+
+char* strlower(char * str){
+     char *temp = str;
+     while(*temp = tolower(*temp))
+         temp++;
+     return str;
+}
+
+int str2bol(char *str){	
+	return 0 == strcmp("true", strlower(str));
+}
+
+jint Parse_Options(JavaVM *vm, JNIEnv *env, jvmtiEnv *jvmti,  const char *agent){
+	PORT_ACCESS_FROM_JAVAVM(vm);
+	VMI_ACCESS_FROM_JAVAVM(vm);
+	
+	AgentList *new_elem = (AgentList *)hymem_allocate_memory(sizeof(AgentList));
+	char *agent_cpy = (char *)hymem_allocate_memory(sizeof(char)*(strlen(agent)+1));
+	char *jar_name, *manifest;
+	char *options = NULL;
+	char *class_name, *bootclasspath, *str_support_redefine;	
+	char *bootclasspath_item;
+	char *classpath;
+	char *classpath_cpy;
+	int support_redefine = 0;
+	char *pos;
+	char *lwrmanifest;
+	
+	strcpy(agent_cpy, agent);
+	//parse jar name and options
+	pos = strchr(agent_cpy, '=');
+	if(pos>0){
+		*pos++ = 0;
+		options = (char *)hymem_allocate_memory(sizeof(char) * (strlen(pos)+1));
+		strcpy(options, pos);
+		hymem_free_memory(pos);
+	}
+	jar_name =agent_cpy;
+
+	//read jar files, find manifest entry and read bytes
+	//read attributes(premain class, support redefine, bootclasspath)
+	manifest = Read_Manifest(vm,env, jar_name);	
+	lwrmanifest = (char *)hymem_allocate_memory(sizeof(char) * (strlen(manifest)+1));
+	strcpy(lwrmanifest,manifest);
+	strlower(lwrmanifest);
+	
+	//jar itself added to bootclasspath
+	check_jvmti_error(env, (*jvmti)->GetSystemProperty(jvmti,"java.class.path",&classpath),"Failed to get classpath.");
+	classpath_cpy = (char *)hymem_allocate_memory((sizeof(char)*(strlen(classpath)+strlen(jar_name)+2)));
+	strcpy(classpath_cpy,classpath);
+	strcat(classpath_cpy,";");
+	strcat(classpath_cpy,jar_name);
+	check_jvmti_error(env, (*jvmti)->SetSystemProperty(jvmti, "java.class.path",classpath_cpy),"Failed to set classpath.");
+	hymem_free_memory(classpath_cpy);
+	hymem_free_memory(jar_name);	
+
+	//save options, save class name, add to agent list
+	class_name = read_attribute(vm, manifest, lwrmanifest,"premain-class");
+	if(NULL == class_name){
+		hymem_free_memory(lwrmanifest);
+		hymem_free_memory(manifest);
+		(*env)->FatalError(env,"Cannot find Premain-Class attribute.");
+	}
+	new_elem->option = options;
+	new_elem->class_name = class_name;
+	new_elem->next = NULL;
+	tail->next = new_elem;
+	tail = new_elem;
+
+	//calculate support redefine
+	str_support_redefine = read_attribute(vm, manifest, lwrmanifest,"can-redefine-classes");
+	if(NULL != str_support_redefine){
+		support_redefine = str2bol(str_support_redefine);	
+		gsupport_redefine |= support_redefine;
+		hymem_free_memory(str_support_redefine);
+	}
+	
+	//add bootclasspath
+	
+	bootclasspath = read_attribute(vm, manifest, lwrmanifest,"boot-class-path");
+	if(NULL != bootclasspath){
+		bootclasspath_item = strtok(bootclasspath, " ");
+		while(NULL != bootclasspath_item){			
+			check_jvmti_error(env, (*jvmti)->AddToBootstrapClassLoaderSearch(jvmti, bootclasspath_item),"Failed to add bootstrap classpath.");			
+			bootclasspath_item = strtok(NULL, " ");
+		}
+		hymem_free_memory(bootclasspath);
+	}	
+	hymem_free_memory(lwrmanifest);
+	hymem_free_memory(manifest);
+	return 0;
+}
+
+JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved){	
+	PORT_ACCESS_FROM_JAVAVM(vm);
+	VMI_ACCESS_FROM_JAVAVM(vm);
+	jint err = (*vm)->GetEnv(vm, (void **)&jnienv, JNI_VERSION_1_2);
+	if(JNI_OK != err){
+		return err;
+	}
+	
+	if(!gdata){		
+		jvmtiCapabilities capabilities;		
+		jvmtiError err;
+		jvmtiEventCallbacks callbacks;
+		JNIEnv *env = NULL;
+		static jvmtiEnv *jvmti;
+
+		gdata = hymem_allocate_memory(sizeof(AgentData));
+		
+		//get jvmti environment
+		err = (*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1_0);
+		if(JNI_OK != err){
+			return err;
+		}		
+		gdata->jvmti = jvmti;
+		
+		//set prerequisite capabilities for classfileloadhook, redefine, and VMInit event
+		memset(&capabilities, 0, sizeof(capabilities));
+		capabilities.can_generate_all_class_hook_events=1;
+		capabilities.can_redefine_classes = 1;
+		//FIXME VM doesnot support the capbility right now.
+		//capabilities.can_redefine_any_class = 1;
+		err = (*jvmti)->AddCapabilities(jvmti, &capabilities);
+		check_jvmti_error(env, err, "Cannot add JVMTI capabilities.");
+
+		//set events callback function
+		(void)memset(&callbacks, 0, sizeof(callbacks));
+		callbacks.ClassFileLoadHook = &callbackClassFileLoadHook;
+		callbacks.VMInit = &callbackVMInit;
+		err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(jvmtiEventCallbacks));
+		check_jvmti_error(env, err, "Cannot set JVMTI event callback functions.");
+
+		//enable classfileloadhook event
+		err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL);
+		check_jvmti_error(env, err, "Cannot set JVMTI VMInit event notification mode.");
+	}		
+	
+	return Parse_Options(vm,jnienv, gdata->jvmti,options);	
+}
+
+JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm){	
+	PORT_ACCESS_FROM_JAVAVM(vm);
+	VMI_ACCESS_FROM_JAVAVM(vm);
+	//free the resource here	
+	if(gdata){
+		jvmtiEnv *jvmti = gdata->jvmti;
+		jvmtiError err = (*jvmti)->DisposeEnvironment(jvmti);
+		if(err != JVMTI_ERROR_NONE)	{
+		   (*jnienv)->FatalError(jnienv,"Cannot dispose JVMTI environment.");		   
+		}		
+		hymem_free_memory(gdata);
+		gdata = NULL;
+	}
+	return;
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/inst_agt.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/instrument.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/instrument.c?view=diff&rev=446488&r1=446487&r2=446488
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/instrument.c (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/instrument.c Thu Sep 14 20:00:01 2006
@@ -1,270 +1,270 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include "instrument.h"
-#include "vmi.h"
-#include "exceptions.h"
-
-
-
-void throw_exception(JNIEnv * env,jvmtiError err){
-      switch (err) {
-        case JVMTI_ERROR_MUST_POSSESS_CAPABILITY:
-            throwNewExceptionByName(env, "java/lang/UnsupportedOperationException",
-                          "The environment does not possess the capability can_redefine_classes."); 
-            return;
-        case JVMTI_ERROR_NULL_POINTER:
-        	throwNewExceptionByName(env, "java/lang/NullPointerException",
-                          "One of class_bytes is NULL.");
-            return;
-        case JVMTI_ERROR_UNMODIFIABLE_CLASS:
-        	throwNewExceptionByName(env, "java/lang/instrument/UnmodifiableClassException",
-                          "An element of class_definitions cannot be modified.");
-            return; 
-        case JVMTI_ERROR_INVALID_CLASS:
-            throwNewExceptionByName(env, "java/lang/ClassNotFoundException",
-                          "An element of class_definitions is not a valid class.");
-            return; 
-        case JVMTI_ERROR_UNSUPPORTED_VERSION:
-        	throwNewExceptionByName(env, "java/lang/UnsupportedClassVersionError",
-                          "A new class file has a version number not supported by this VM.");
-            return; 
-        case JVMTI_ERROR_INVALID_CLASS_FORMAT:
-        	throwNewExceptionByName(env, "java/lang/ClassFormatError",
-                          "A new class file is malformed.");
-            return; 
-        case JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION:
-        	throwNewExceptionByName(env, "java/lang/ClassCircularityError",
-                          "The new class file definitions would lead to a circular definition.");
-            return; 
-        case JVMTI_ERROR_FAILS_VERIFICATION:
-            throwNewExceptionByName(env, "java/lang/ClassFormatError",
-                          "The class bytes fail verification.");
-            return; 
-        case JVMTI_ERROR_NAMES_DONT_MATCH:
-        	throwNewExceptionByName(env, "java/lang/NoClassDefFoundError",
-                          "The class name defined in a new class file is different from the name in the old class object.");
-            return; 
-        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED:
-            throwNewExceptionByName(env, "java/lang/UnsupportedOperationException",
-                          "A new class file requires adding a method.");
-            return; 
-        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED:
-            throwNewExceptionByName(env, "java/lang/UnsupportedOperationException",
-                    "A new class version changes a field.");
-            return; 
-        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED:
-            throwNewExceptionByName(env, "java/lang/UnsupportedOperationException",
-                    "A direct superclass is different for a new class version, or the set of directly implemented interfaces is different.");
-            return; 
-        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED:
-            throwNewExceptionByName(env, "java/lang/UnsupportedOperationException",
-                    "A new class version does not declare a method declared in the old class version.");
-            return; 
-        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED:
-            throwNewExceptionByName(env, "java/lang/UnsupportedOperationException",
-                    "A new class version has different modifiers.");
-            return; 
-        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED:
-            throwNewExceptionByName(env, "java/lang/UnsupportedOperationException",
-                    "A method in the new class version has different modifiers than its counterpart in the old class version.");
-            return; 
-        default:
-            throwNewExceptionByName(env, "java/lang/InternalError",
-                    "Unknown error during redefinition."); 
-        }
-}
-
-/*
- * This file contains native methods implementation for org/apache/harmony/instrument/internal/InstrumentationImpl
- */
-
-jobjectArray extract_elements(JNIEnv *env, jvmtiEnv *jvmti, jint count, const jclass* classes_ptr){
-	  jclass klass;
-	  jobjectArray classes;
-	  int index;
-	  jvmtiError err;
-		
-	  //get the class of "java.lang.Class" in java language
-	  klass= (*env)->FindClass(env, "java/lang/Class");
-	  if(NULL == klass){
-		return NULL;
-	  }
-	
-	  //initiate the object array to return, fill in all elements with the same value
-	  classes = (*env)->NewObjectArray(env, count, klass, NULL);
-	  if(NULL == classes){
-		  return NULL;
-	  }
-	
-	  //fill in the object array with right values
-	  for(index=0; index<count; index++){
-		  (*env)->SetObjectArrayElement(env, classes, index, classes_ptr[index]);
-	  }
-
-	  err = (*jvmti)->Deallocate(jvmti,(unsigned char *)classes_ptr);
-	  check_jvmti_error(env, err, "Cannot deallocate memory.");
-
-	  return classes;
-}
-
-/*
- * Class:     Java_org_apache_harmony_instrument_internal_InstrumentationImpl
- * Method:    getAllLoadedClasses
- * Signature: ()[Ljava/lang/Class;
- */
-JNIEXPORT jobjectArray JNICALL Java_org_apache_harmony_instrument_internal_InstrumentationImpl_getAllLoadedClasses
-  (JNIEnv* env, jobject objThis){
-	  jvmtiEnv* jvmti=gdata->jvmti;
-	  jint count=0;
-	  jclass* classes_ptr=NULL;
-      jobjectArray classes; //the object array to return
-	  
-	  jvmtiError err = (*jvmti)->GetLoadedClasses(jvmti, &count, &classes_ptr);
-	  check_jvmti_error(env, err, "Cannot get loaded classes.");
-
-	  classes = extract_elements(env, jvmti, count, classes_ptr);
-
-	  return classes;
-}
-
-
-/*
- * Class:     Java_org_apache_harmony_instrument_internal_InstrumentationImpl
- * Method:    getInitiatedClasses
- * Signature: (Ljava/lang/ClassLoader;)[Ljava/lang/Class;
- */
-JNIEXPORT jobjectArray JNICALL Java_org_apache_harmony_instrument_internal_InstrumentationImpl_getInitiatedClasses
-  (JNIEnv * env, jobject objThis, jobject loader){
-	  jvmtiEnv* jvmti=gdata->jvmti;
-	  jint count=0;
-	  jclass* classes_ptr=NULL;
-      jobjectArray classes; 
-
-	  jvmtiError err = (*jvmti)->GetClassLoaderClasses(jvmti, loader, &count, &classes_ptr);
-	  check_jvmti_error(env, err, "Cannot get loaded classes for this classloader.");
-
-	  classes = extract_elements(env, jvmti, count, classes_ptr);
-
-	  return classes;
-}
-
-/*
- * Class:     Java_org_apache_harmony_instrument_internal_InstrumentationImpl
- * Method:    getObjectSize_native
- * Signature: (Ljava/lang/Object;)J
- */
-JNIEXPORT jlong JNICALL Java_org_apache_harmony_instrument_internal_InstrumentationImpl_getObjectSize_1native
-  (JNIEnv * env, jobject objThis, jobject objToSize){
-	  jvmtiEnv *jvmti=gdata->jvmti;
-	  jlong size=0l; 
-	  jvmtiError err=(*jvmti)->GetObjectSize(jvmti, objToSize, &size);
-	  check_jvmti_error(env, err, "Cannot get object size.");
-	  return size;
-}
-
-/*
- * Class:     Java_org_apache_harmony_instrument_internal_InstrumentationImpl
- * Method:    redefineClasses_native
- * Signature: ([Ljava/lang/instrument/ClassDefinition;)V
- */
-JNIEXPORT void JNICALL Java_org_apache_harmony_instrument_internal_InstrumentationImpl_redefineClasses_1native
-  (JNIEnv * env, jobject objThis, jobjectArray javaClassDefArr){
-      PORT_ACCESS_FROM_ENV (env);
-	  jvmtiEnv* jvmti=gdata->jvmti;
-	  int err; 
-	  int index;
-	  jmethodID method_get_class;
-	  jmethodID method_get_data;
-	  jsize length;
-	  jvmtiClassDefinition *class_definitions;	  
-	  int i=0;
-	  jclass clz;
-	  jmethodID method_clear;
-
-	  //locate the java methods needed by class definition data extraction
-	  jclass class_ClassDefinition=(*env)->FindClass(env, "java/lang/instrument/ClassDefinition");
-	  if(NULL == class_ClassDefinition){
-		return;
-	  }
-
-	  method_get_data=(*env)->GetMethodID(env, class_ClassDefinition, "getDefinitionClassFile", "()[B");
-	  if(NULL == method_get_data){
-		return;
-	  }
-	  
-	  method_get_class=(*env)->GetMethodID(env, class_ClassDefinition, "getDefinitionClass", "()Ljava/lang/Class;");
-	  if(NULL == method_get_class){
-		return;
-	  }
-
-	  //allocate memory for native jvmtiClassDefinition structs to hold class redefinition data
-	  length=(*env)->GetArrayLength(env, javaClassDefArr);
-	  class_definitions=(jvmtiClassDefinition*) hymem_allocate_memory(sizeof(jvmtiClassDefinition)*length);
-	  if(NULL == class_definitions){
-	  	return;
-	  }
-	  
-	  //extract class definition data from java array into native array
-	  for(index=0; index<length; index++){
-		  int class_byte_count; 
-		  jobject obj_ClassDefinition=(*env)->GetObjectArrayElement(env, javaClassDefArr, index); 		  
-		  jbyteArray jclass_bytes;
-		  jboolean copy;
-		  jbyte* class_bytes;
-		  jclass klass=(jclass)(*env)->CallObjectMethod(env, obj_ClassDefinition, method_get_class);
-		  if (NULL == klass){
-		    hymem_free_memory(class_definitions);
-		  	return;
-		  }
-		  jclass_bytes =(jbyteArray)(*env)->CallObjectMethod(env, obj_ClassDefinition, method_get_data);
-		  copy = JNI_TRUE;
-		  class_bytes = (*env)->GetByteArrayElements(env, jclass_bytes, &copy);
-		  if(NULL == class_bytes){
-			hymem_free_memory(class_definitions);
-			return;
-		  }
-		  class_byte_count = (*env)->GetArrayLength(env, jclass_bytes);
-          if(copy == JNI_TRUE){
-		    (*env)->ReleaseByteArrayElements(env,jclass_bytes, class_bytes, JNI_ABORT);
-          }
-	  
-		  //construct a jvmtiClassDefinition element		  
-		  class_definitions[index].klass=klass;
-		  class_definitions[index].class_bytes=class_bytes;
-		  class_definitions[index].class_byte_count=class_byte_count;
-	  }
-
-	  //perform redefinition
-	  err=(*jvmti)->RedefineClasses(jvmti, length, class_definitions);
-
-	  if (JVMTI_ERROR_NONE!=err){
-	  	  clz= (*env)->FindClass(env, "org/apache/harmony/instrument/internal/InstrumentationImpl");
-	  	  method_clear=(*env)->GetMethodID(env, clz, "clear", "()V");
-	  	  (*env)->CallVoidMethod(env,objThis,method_clear);
-	      throw_exception(env,err);
-	  }
-	  //free memory
-	  hymem_free_memory(class_definitions);
-	  return;
-}
-
-void check_jvmti_error(JNIEnv *env, jvmtiError error, const char *msg){
-	if(error != JVMTI_ERROR_NONE){
-		(*env)->FatalError(env,msg);
-	}
-	return;
-}
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include "instrument.h"
+#include "vmi.h"
+#include "exceptions.h"
+
+
+
+void throw_exception(JNIEnv * env,jvmtiError err){
+      switch (err) {
+        case JVMTI_ERROR_MUST_POSSESS_CAPABILITY:
+            throwNewExceptionByName(env, "java/lang/UnsupportedOperationException",
+                          "The environment does not possess the capability can_redefine_classes."); 
+            return;
+        case JVMTI_ERROR_NULL_POINTER:
+        	throwNewExceptionByName(env, "java/lang/NullPointerException",
+                          "One of class_bytes is NULL.");
+            return;
+        case JVMTI_ERROR_UNMODIFIABLE_CLASS:
+        	throwNewExceptionByName(env, "java/lang/instrument/UnmodifiableClassException",
+                          "An element of class_definitions cannot be modified.");
+            return; 
+        case JVMTI_ERROR_INVALID_CLASS:
+            throwNewExceptionByName(env, "java/lang/ClassNotFoundException",
+                          "An element of class_definitions is not a valid class.");
+            return; 
+        case JVMTI_ERROR_UNSUPPORTED_VERSION:
+        	throwNewExceptionByName(env, "java/lang/UnsupportedClassVersionError",
+                          "A new class file has a version number not supported by this VM.");
+            return; 
+        case JVMTI_ERROR_INVALID_CLASS_FORMAT:
+        	throwNewExceptionByName(env, "java/lang/ClassFormatError",
+                          "A new class file is malformed.");
+            return; 
+        case JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION:
+        	throwNewExceptionByName(env, "java/lang/ClassCircularityError",
+                          "The new class file definitions would lead to a circular definition.");
+            return; 
+        case JVMTI_ERROR_FAILS_VERIFICATION:
+            throwNewExceptionByName(env, "java/lang/ClassFormatError",
+                          "The class bytes fail verification.");
+            return; 
+        case JVMTI_ERROR_NAMES_DONT_MATCH:
+        	throwNewExceptionByName(env, "java/lang/NoClassDefFoundError",
+                          "The class name defined in a new class file is different from the name in the old class object.");
+            return; 
+        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED:
+            throwNewExceptionByName(env, "java/lang/UnsupportedOperationException",
+                          "A new class file requires adding a method.");
+            return; 
+        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED:
+            throwNewExceptionByName(env, "java/lang/UnsupportedOperationException",
+                    "A new class version changes a field.");
+            return; 
+        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED:
+            throwNewExceptionByName(env, "java/lang/UnsupportedOperationException",
+                    "A direct superclass is different for a new class version, or the set of directly implemented interfaces is different.");
+            return; 
+        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED:
+            throwNewExceptionByName(env, "java/lang/UnsupportedOperationException",
+                    "A new class version does not declare a method declared in the old class version.");
+            return; 
+        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED:
+            throwNewExceptionByName(env, "java/lang/UnsupportedOperationException",
+                    "A new class version has different modifiers.");
+            return; 
+        case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED:
+            throwNewExceptionByName(env, "java/lang/UnsupportedOperationException",
+                    "A method in the new class version has different modifiers than its counterpart in the old class version.");
+            return; 
+        default:
+            throwNewExceptionByName(env, "java/lang/InternalError",
+                    "Unknown error during redefinition."); 
+        }
+}
+
+/*
+ * This file contains native methods implementation for org/apache/harmony/instrument/internal/InstrumentationImpl
+ */
+
+jobjectArray extract_elements(JNIEnv *env, jvmtiEnv *jvmti, jint count, const jclass* classes_ptr){
+	  jclass klass;
+	  jobjectArray classes;
+	  int index;
+	  jvmtiError err;
+		
+	  //get the class of "java.lang.Class" in java language
+	  klass= (*env)->FindClass(env, "java/lang/Class");
+	  if(NULL == klass){
+		return NULL;
+	  }
+	
+	  //initiate the object array to return, fill in all elements with the same value
+	  classes = (*env)->NewObjectArray(env, count, klass, NULL);
+	  if(NULL == classes){
+		  return NULL;
+	  }
+	
+	  //fill in the object array with right values
+	  for(index=0; index<count; index++){
+		  (*env)->SetObjectArrayElement(env, classes, index, classes_ptr[index]);
+	  }
+
+	  err = (*jvmti)->Deallocate(jvmti,(unsigned char *)classes_ptr);
+	  check_jvmti_error(env, err, "Cannot deallocate memory.");
+
+	  return classes;
+}
+
+/*
+ * Class:     Java_org_apache_harmony_instrument_internal_InstrumentationImpl
+ * Method:    getAllLoadedClasses
+ * Signature: ()[Ljava/lang/Class;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_apache_harmony_instrument_internal_InstrumentationImpl_getAllLoadedClasses
+  (JNIEnv* env, jobject objThis){
+	  jvmtiEnv* jvmti=gdata->jvmti;
+	  jint count=0;
+	  jclass* classes_ptr=NULL;
+      jobjectArray classes; //the object array to return
+	  
+	  jvmtiError err = (*jvmti)->GetLoadedClasses(jvmti, &count, &classes_ptr);
+	  check_jvmti_error(env, err, "Cannot get loaded classes.");
+
+	  classes = extract_elements(env, jvmti, count, classes_ptr);
+
+	  return classes;
+}
+
+
+/*
+ * Class:     Java_org_apache_harmony_instrument_internal_InstrumentationImpl
+ * Method:    getInitiatedClasses
+ * Signature: (Ljava/lang/ClassLoader;)[Ljava/lang/Class;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_apache_harmony_instrument_internal_InstrumentationImpl_getInitiatedClasses
+  (JNIEnv * env, jobject objThis, jobject loader){
+	  jvmtiEnv* jvmti=gdata->jvmti;
+	  jint count=0;
+	  jclass* classes_ptr=NULL;
+      jobjectArray classes; 
+
+	  jvmtiError err = (*jvmti)->GetClassLoaderClasses(jvmti, loader, &count, &classes_ptr);
+	  check_jvmti_error(env, err, "Cannot get loaded classes for this classloader.");
+
+	  classes = extract_elements(env, jvmti, count, classes_ptr);
+
+	  return classes;
+}
+
+/*
+ * Class:     Java_org_apache_harmony_instrument_internal_InstrumentationImpl
+ * Method:    getObjectSize_native
+ * Signature: (Ljava/lang/Object;)J
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_instrument_internal_InstrumentationImpl_getObjectSize_1native
+  (JNIEnv * env, jobject objThis, jobject objToSize){
+	  jvmtiEnv *jvmti=gdata->jvmti;
+	  jlong size=0l; 
+	  jvmtiError err=(*jvmti)->GetObjectSize(jvmti, objToSize, &size);
+	  check_jvmti_error(env, err, "Cannot get object size.");
+	  return size;
+}
+
+/*
+ * Class:     Java_org_apache_harmony_instrument_internal_InstrumentationImpl
+ * Method:    redefineClasses_native
+ * Signature: ([Ljava/lang/instrument/ClassDefinition;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_harmony_instrument_internal_InstrumentationImpl_redefineClasses_1native
+  (JNIEnv * env, jobject objThis, jobjectArray javaClassDefArr){
+      PORT_ACCESS_FROM_ENV (env);
+	  jvmtiEnv* jvmti=gdata->jvmti;
+	  int err; 
+	  int index;
+	  jmethodID method_get_class;
+	  jmethodID method_get_data;
+	  jsize length;
+	  jvmtiClassDefinition *class_definitions;	  
+	  int i=0;
+	  jclass clz;
+	  jmethodID method_clear;
+
+	  //locate the java methods needed by class definition data extraction
+	  jclass class_ClassDefinition=(*env)->FindClass(env, "java/lang/instrument/ClassDefinition");
+	  if(NULL == class_ClassDefinition){
+		return;
+	  }
+
+	  method_get_data=(*env)->GetMethodID(env, class_ClassDefinition, "getDefinitionClassFile", "()[B");
+	  if(NULL == method_get_data){
+		return;
+	  }
+	  
+	  method_get_class=(*env)->GetMethodID(env, class_ClassDefinition, "getDefinitionClass", "()Ljava/lang/Class;");
+	  if(NULL == method_get_class){
+		return;
+	  }
+
+	  //allocate memory for native jvmtiClassDefinition structs to hold class redefinition data
+	  length=(*env)->GetArrayLength(env, javaClassDefArr);
+	  class_definitions=(jvmtiClassDefinition*) hymem_allocate_memory(sizeof(jvmtiClassDefinition)*length);
+	  if(NULL == class_definitions){
+	  	return;
+	  }
+	  
+	  //extract class definition data from java array into native array
+	  for(index=0; index<length; index++){
+		  int class_byte_count; 
+		  jobject obj_ClassDefinition=(*env)->GetObjectArrayElement(env, javaClassDefArr, index); 		  
+		  jbyteArray jclass_bytes;
+		  jboolean copy;
+		  jbyte* class_bytes;
+		  jclass klass=(jclass)(*env)->CallObjectMethod(env, obj_ClassDefinition, method_get_class);
+		  if (NULL == klass){
+		    hymem_free_memory(class_definitions);
+		  	return;
+		  }
+		  jclass_bytes =(jbyteArray)(*env)->CallObjectMethod(env, obj_ClassDefinition, method_get_data);
+		  copy = JNI_TRUE;
+		  class_bytes = (*env)->GetByteArrayElements(env, jclass_bytes, &copy);
+		  if(NULL == class_bytes){
+			hymem_free_memory(class_definitions);
+			return;
+		  }
+		  class_byte_count = (*env)->GetArrayLength(env, jclass_bytes);
+          if(copy == JNI_TRUE){
+		    (*env)->ReleaseByteArrayElements(env,jclass_bytes, class_bytes, JNI_ABORT);
+          }
+	  
+		  //construct a jvmtiClassDefinition element		  
+		  class_definitions[index].klass=klass;
+		  class_definitions[index].class_bytes=class_bytes;
+		  class_definitions[index].class_byte_count=class_byte_count;
+	  }
+
+	  //perform redefinition
+	  err=(*jvmti)->RedefineClasses(jvmti, length, class_definitions);
+
+	  if (JVMTI_ERROR_NONE!=err){
+	  	  clz= (*env)->FindClass(env, "org/apache/harmony/instrument/internal/InstrumentationImpl");
+	  	  method_clear=(*env)->GetMethodID(env, clz, "clear", "()V");
+	  	  (*env)->CallVoidMethod(env,objThis,method_clear);
+	      throw_exception(env,err);
+	  }
+	  //free memory
+	  hymem_free_memory(class_definitions);
+	  return;
+}
+
+void check_jvmti_error(JNIEnv *env, jvmtiError error, const char *msg){
+	if(error != JVMTI_ERROR_NONE){
+		(*env)->FatalError(env,msg);
+	}
+	return;
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/instrument.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/instrument.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/instrument.h?view=diff&rev=446488&r1=446487&r2=446488
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/instrument.h (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/instrument.h Thu Sep 14 20:00:01 2006
@@ -1,81 +1,81 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* DO NOT EDIT THIS FILE - it is machine generated */
-#include <jvmti.h>
-#include <jni.h>
-/* Header for class org_apache_harmony_instrument_internal_InstrumentationImpl */
-
-#ifndef _Included_org_apache_harmony_instrument_internal_InstrumentationImpl
-#define _Included_org_apache_harmony_instrument_internal_InstrumentationImpl
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct{
-	jvmtiEnv *jvmti;
-	jobject *inst;
-	jclass *inst_class;
-	jmethodID *transform_method;
-	jmethodID *premain_method;
-} AgentData;
-
-typedef struct AgentList{
-	char *class_name;
-	char *option;
-	struct AgentList *next;
-}AgentList;
-
-AgentList list;
-AgentData *gdata;
-	
-/*
- * Class:     org_apache_harmony_instrument_internal_InstrumentationImpl
- * Method:    redefineClasses_native
- * Signature: ([Ljava/lang/instrument/ClassDefinition;)V
- */
-JNIEXPORT void JNICALL Java_org_apache_harmony_instrument_internal_InstrumentationImpl_redefineClasses_1native
-  (JNIEnv *, jobject, jobjectArray);
-
-/*
- * Class:     org_apache_harmony_instrument_internal_InstrumentationImpl
- * Method:    getAllLoadedClasses
- * Signature: ()[Ljava/lang/Class;
- */
-JNIEXPORT jobjectArray JNICALL Java_org_apache_harmony_instrument_internal_InstrumentationImpl_getAllLoadedClasses
-  (JNIEnv *, jobject);
-
-/*
- * Class:     org_apache_harmony_instrument_internal_InstrumentationImpl
- * Method:    getInitiatedClasses
- * Signature: (Ljava/lang/ClassLoader;)[Ljava/lang/Class;
- */
-JNIEXPORT jobjectArray JNICALL Java_org_apache_harmony_instrument_internal_InstrumentationImpl_getInitiatedClasses
-  (JNIEnv *, jobject, jobject);
-
-/*
- * Class:     org_apache_harmony_instrument_internal_InstrumentationImpl
- * Method:    getObjectSize_native
- * Signature: (Ljava/lang/Object;)J
- */
-JNIEXPORT jlong JNICALL Java_org_apache_harmony_instrument_internal_InstrumentationImpl_getObjectSize_1native
-  (JNIEnv *, jobject, jobject);
-
-void check_jvmti_error(JNIEnv *, jvmtiError, const char *);
-#ifdef __cplusplus
-}
-#endif
-#endif
-
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jvmti.h>
+#include <jni.h>
+/* Header for class org_apache_harmony_instrument_internal_InstrumentationImpl */
+
+#ifndef _Included_org_apache_harmony_instrument_internal_InstrumentationImpl
+#define _Included_org_apache_harmony_instrument_internal_InstrumentationImpl
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct{
+	jvmtiEnv *jvmti;
+	jobject *inst;
+	jclass *inst_class;
+	jmethodID *transform_method;
+	jmethodID *premain_method;
+} AgentData;
+
+typedef struct AgentList{
+	char *class_name;
+	char *option;
+	struct AgentList *next;
+}AgentList;
+
+AgentList list;
+AgentData *gdata;
+	
+/*
+ * Class:     org_apache_harmony_instrument_internal_InstrumentationImpl
+ * Method:    redefineClasses_native
+ * Signature: ([Ljava/lang/instrument/ClassDefinition;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_harmony_instrument_internal_InstrumentationImpl_redefineClasses_1native
+  (JNIEnv *, jobject, jobjectArray);
+
+/*
+ * Class:     org_apache_harmony_instrument_internal_InstrumentationImpl
+ * Method:    getAllLoadedClasses
+ * Signature: ()[Ljava/lang/Class;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_apache_harmony_instrument_internal_InstrumentationImpl_getAllLoadedClasses
+  (JNIEnv *, jobject);
+
+/*
+ * Class:     org_apache_harmony_instrument_internal_InstrumentationImpl
+ * Method:    getInitiatedClasses
+ * Signature: (Ljava/lang/ClassLoader;)[Ljava/lang/Class;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_apache_harmony_instrument_internal_InstrumentationImpl_getInitiatedClasses
+  (JNIEnv *, jobject, jobject);
+
+/*
+ * Class:     org_apache_harmony_instrument_internal_InstrumentationImpl
+ * Method:    getObjectSize_native
+ * Signature: (Ljava/lang/Object;)J
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_instrument_internal_InstrumentationImpl_getObjectSize_1native
+  (JNIEnv *, jobject, jobject);
+
+void check_jvmti_error(JNIEnv *, jvmtiError, const char *);
+#ifdef __cplusplus
+}
+#endif
+#endif
+

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/instrument.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/AllTests.java?view=diff&rev=446488&r1=446487&r2=446488
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/AllTests.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/AllTests.java Thu Sep 14 20:00:01 2006
@@ -1,34 +1,34 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.tests.java.lang.instrument;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
-
-    public static Test suite() {
-        TestSuite suite = new TestSuite(
-                "Test for org.apache.harmony.tests.java.lang.instrument");
-        //$JUnit-BEGIN$
-        suite.addTestSuite(IllegalClassFormatExceptionTest.class);
-        suite.addTestSuite(UnmodifiableClassExceptionTest.class);
-        suite.addTestSuite(ClassDefinitionTest.class);
-        //$JUnit-END$
-        return suite;
-    }
-
-}
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.lang.instrument;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite(
+                "Test for org.apache.harmony.tests.java.lang.instrument");
+        //$JUnit-BEGIN$
+        suite.addTestSuite(IllegalClassFormatExceptionTest.class);
+        suite.addTestSuite(UnmodifiableClassExceptionTest.class);
+        suite.addTestSuite(ClassDefinitionTest.class);
+        //$JUnit-END$
+        return suite;
+    }
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/AllTests.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/ClassDefinitionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/ClassDefinitionTest.java?view=diff&rev=446488&r1=446487&r2=446488
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/ClassDefinitionTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/ClassDefinitionTest.java Thu Sep 14 20:00:01 2006
@@ -1,67 +1,67 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.tests.java.lang.instrument;
-
-import java.lang.instrument.ClassDefinition;
-
-import junit.framework.TestCase;
-
-public class ClassDefinitionTest extends TestCase {
-
-    /**
-     * @tests java.lang.instrument.ClassDefinition#ClassDefinition(Class<?>, byte[])
-     */
-    public void test_ConstructorLClass$B() {
-        try{
-            new ClassDefinition(null,null);
-            fail("Should throw NullPointerException");
-        } catch (NullPointerException e) {
-            // expected
-        }
-        try{
-            new ClassDefinition(null,new byte[0]);
-            fail("Should throw NullPointerException");
-        } catch (NullPointerException e) {
-            // expected
-        }
-        try{
-            new ClassDefinition(this.getClass(),null);
-            fail("Should throw NullPointerException");
-        } catch (NullPointerException e) {
-            // expected
-        }
-    }
-
-    /**
-     * @tests java.lang.instrument.ClassDefinition#getDefinitionClass()
-     */
-    public void test_getDefinitionClass() {
-        ClassDefinition cd = new ClassDefinition(this.getClass(),new byte[0]);
-        assertSame(this.getClass(),cd.getDefinitionClass());
-    }
-
-    /**
-     * @tests java.lang.instrument.ClassDefinition#getDefinitionClassFile()
-     */
-    public void test_getDefinitionClassFile() {
-        byte[] emptyByteArray = new byte[0];
-        byte[] someByteArray = new byte[1024];
-        ClassDefinition cd = new ClassDefinition(this.getClass(),emptyByteArray);
-        assertSame(emptyByteArray,cd.getDefinitionClassFile());        
-        cd = new ClassDefinition(this.getClass(),someByteArray);
-        assertSame(someByteArray,cd.getDefinitionClassFile());        
-    }
-}
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.lang.instrument;
+
+import java.lang.instrument.ClassDefinition;
+
+import junit.framework.TestCase;
+
+public class ClassDefinitionTest extends TestCase {
+
+    /**
+     * @tests java.lang.instrument.ClassDefinition#ClassDefinition(Class<?>, byte[])
+     */
+    public void test_ConstructorLClass$B() {
+        try{
+            new ClassDefinition(null,null);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        try{
+            new ClassDefinition(null,new byte[0]);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        try{
+            new ClassDefinition(this.getClass(),null);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests java.lang.instrument.ClassDefinition#getDefinitionClass()
+     */
+    public void test_getDefinitionClass() {
+        ClassDefinition cd = new ClassDefinition(this.getClass(),new byte[0]);
+        assertSame(this.getClass(),cd.getDefinitionClass());
+    }
+
+    /**
+     * @tests java.lang.instrument.ClassDefinition#getDefinitionClassFile()
+     */
+    public void test_getDefinitionClassFile() {
+        byte[] emptyByteArray = new byte[0];
+        byte[] someByteArray = new byte[1024];
+        ClassDefinition cd = new ClassDefinition(this.getClass(),emptyByteArray);
+        assertSame(emptyByteArray,cd.getDefinitionClassFile());        
+        cd = new ClassDefinition(this.getClass(),someByteArray);
+        assertSame(someByteArray,cd.getDefinitionClassFile());        
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/ClassDefinitionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/IllegalClassFormatExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/IllegalClassFormatExceptionTest.java?view=diff&rev=446488&r1=446487&r2=446488
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/IllegalClassFormatExceptionTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/IllegalClassFormatExceptionTest.java Thu Sep 14 20:00:01 2006
@@ -1,41 +1,41 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.tests.java.lang.instrument;
-
-import java.lang.instrument.IllegalClassFormatException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-public class IllegalClassFormatExceptionTest extends TestCase {
-
-    /**
-     * @tests serialization/deserialization compatibility.
-     */
-    public void test_serialization() throws Exception {
-        IllegalClassFormatException object = new IllegalClassFormatException();
-        SerializationTest.verifySelf(object);
-    }
-
-    /**
-     * @tests serialization/deserialization compatibility with RI.
-     */
-    public void test_compatibilitySerialization() throws Exception {
-        IllegalClassFormatException object = new IllegalClassFormatException();
-        SerializationTest.verifyGolden(this, object);        
-    }
-}
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.lang.instrument;
+
+import java.lang.instrument.IllegalClassFormatException;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.testframework.serialization.SerializationTest;
+
+public class IllegalClassFormatExceptionTest extends TestCase {
+
+    /**
+     * @tests serialization/deserialization compatibility.
+     */
+    public void test_serialization() throws Exception {
+        IllegalClassFormatException object = new IllegalClassFormatException();
+        SerializationTest.verifySelf(object);
+    }
+
+    /**
+     * @tests serialization/deserialization compatibility with RI.
+     */
+    public void test_compatibilitySerialization() throws Exception {
+        IllegalClassFormatException object = new IllegalClassFormatException();
+        SerializationTest.verifyGolden(this, object);        
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/IllegalClassFormatExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message