harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paulex Yang (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-1194) [classlib][nio] unexpected "Memory Spy! Fixed attempt to free memory that was not allocated PlatformAddress[xxx]" messages
Date Mon, 05 Mar 2007 03:32:51 GMT

    [ https://issues.apache.org/jira/browse/HARMONY-1194?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12477894
] 

Paulex Yang commented on HARMONY-1194:
--------------------------------------

Hi, Ruth, 

I had a look at the harmony-1194-2.diff, but I'm not sure this patch can fix the issues, which
I think is caused by the racing condition between orphanedMemory(Reference) and free(PlatformAddress),
consider the situation below:

Thread A runs into MemorySpy.orphanedMemory(Reference) and get non-null "wrapper" by "shadow",
at this time Thread B runs into MemorySpy.free(PlatformAddress) and removed same "shadow"
from the HashMap "memoryInUse", then when Thread A runs into "wrapper".free() and MemorySpy.free(PlatformAddress),
it will find that "shadow" doesn't exist and reports error message as above. 

So, my proposal is, extend synchronized(this) block in MemorySpy.orphanedMemory(Reference
ref) to include wrapper.shadow.free(),  so that the racing condition can be avoid.  I'll upload
a diff file soon for details.


> [classlib][nio] unexpected "Memory Spy! Fixed attempt to free memory that was not allocated
PlatformAddress[xxx]" messages
> --------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-1194
>                 URL: https://issues.apache.org/jira/browse/HARMONY-1194
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Vladimir Ivanov
>         Assigned To: Tim Ellison
>         Attachments: Harmony-1194-2.diff, Harmony-1194.diff
>
>
> The test below report on the 2CPU computers messages like this
> "Memory Spy! Fixed attempt to free memory that was not allocated PlatformAddress[159703592]"
> Note, on 1 CPU it works fine. I did not detect problem yet so continue to investigate.
> ============================= test.java ===========================
> import java.io.File;
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.nio.ByteBuffer;
> import java.nio.channels.FileChannel;
> public class test {
>     public int NUMBER_OF_ITERATIONS = 10000;
>     public int NUMBER_OF_BYTE_BUFFERS = 3;
>     public int bufferSize = 1024;
>     public int numThreads = 15;
>     // Each thread sets PASS/FAIL flag into its corresponding array element
>     public int[] statuses;
>     public static void main(String[] args) {
>         System.exit(new test().test(args));
>     }
>     public int test(String[] params) {
>         // Start 'numThreads' threads each reading from file, inflating/deflating
>         Thread[] t = new Thread[numThreads];
>         statuses = new int[t.length];
>                                 
>         for (int i = 0; i < t.length; i++) {
>             t[i] = new Thread(new ChannelWriteThread(i, this));
>             t[i].start();
>             System.out.println("Thread " + i + " started");
>         }
>                 
>         // wait for all threads to finish
>         for (int i = 0; i < t.length; ++i){
>              try {
>                  t[i].join();
>                  System.out.println("Thread " + i + ": joined() ");
>              } catch (InterruptedException ie){
>                  System.out.println("interruptedException while join() of thread #" +
i);
>                  return -1;
>              }
>          }
>          // check status
>          for (int i = 0; i < statuses.length; ++i){
>              if (statuses[i] != 10){
>                  System.out.println("thread #" + i + " returned not PASS status");
>                  return -1;
>              }
>          }
>         System.out.println("OK");
>         return 0;
>     }
> }
> class ChannelWriteThread implements Runnable {
>     public int id;
>     public test base;
>     public ChannelWriteThread(int id, test base) {
>         this.id = id;
>         this.base = base;
>     }
>     public void run() {
>         FileOutputStream fos = null;
>         FileChannel channel = null;
>         try {
>             File file = File.createTempFile("test", null);
>             file.deleteOnExit();
>             fos = new FileOutputStream(file);
>             channel = fos.getChannel();
>         } catch (IOException e) {
>             e.printStackTrace();
>         } 
>         base.statuses[id] = 10;
>         ByteBuffer[] buffer = new ByteBuffer[base.NUMBER_OF_BYTE_BUFFERS];
>         for (int i = 0; i < base.NUMBER_OF_ITERATIONS; ++i) {
>             for(int j = 0; j < base.NUMBER_OF_BYTE_BUFFERS; j++) {
>                 buffer[j] = ByteBuffer.allocate(2 * base.bufferSize); 
>             }
>             buffer[0].flip(); 
>             try {
>                 channel.write(buffer);  
>             } catch (IOException e) {
>                 base.statuses[id] = -1;
>                 System.out.println("Thread " + id + " : IOException while buffer writing");
>             }
>             buffer[0].clear();
>         }
>         try {
>             channel.close();
>             fos.close();
>         } catch (IOException e) {
>             base.statuses[id] = -1;
>             System.out.println("Thread " + id + " : IOException while closing");
>         }
>     }
> }
> ===============================================================
> Output (for 4 CPU comp):
> Y:\site\proj\drl\qe\my>inaries\builds\combined\20060815\Harmony-drlvm_20060815_win_ia32_0000_msvc\bin\java.exe
-Dvm.assert_dialog=false -cp . -showversion test
> java version "1.5.0"
> pre-alpha : not complete or compatible
> svn = rsvn: '.' is not a working copy, (Aug 15 2006), Windows/ia32/msvc 1310, debug build
> http://incubator.apache.org/harmony
> Thread 0 started
> Thread 1 started
> Thread 2 started
> Thread 3 started
> Thread 4 started
> Thread 5 started
> Thread 6 started
> Thread 7 started
> Thread 8 started
> Thread 9 started
> Thread 10 started
> Thread 11 started
> Thread 12 started
> Thread 13 started
> Thread 14 started
> Memory Spy! Fixed attempt to free memory that was not allocated PlatformAddress[187955296]
> Memory Spy! Fixed attempt to free memory that was not allocated PlatformAddress[161934880]
> Memory Spy! Fixed attempt to free memory that was not allocated PlatformAddress[175398240]
> Memory Spy! Fixed attempt to free memory that was not allocated PlatformAddress[168220896]
> Memory Spy! Fixed attempt to free memory that was not allocated PlatformAddress[161925840]
> Memory Spy! Fixed attempt to free memory that was not allocated PlatformAddress[172589448]
> Memory Spy! Fixed attempt to free memory that was not allocated PlatformAddress[190659456]
> Memory Spy! Fixed attempt to free memory that was not allocated PlatformAddress[200620192]
> Memory Spy! Fixed attempt to free memory that was not allocated PlatformAddress[171946168]
> Memory Spy! Fixed attempt to free memory that was not allocated PlatformAddress[192747808]
> Thread 0: joined()
> Memory Spy! Fixed attempt to free memory that was not allocated PlatformAddress[172558608]
> Thread 1: joined()
> Thread 2: joined()
> Thread 3: joined()
> Thread 4: joined()
> Thread 5: joined()
> Thread 6: joined()
> Thread 7: joined()
> Thread 8: joined()
> Thread 9: joined()
> Thread 10: joined()
> Thread 11: joined()
> Thread 12: joined()
> Thread 13: joined()
> Thread 14: joined()
> OK

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message