1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19/** 20* @author Anatoly F. Bondarenko 21*/ 22 23/** 24* Created on 04.03.2005 25*/ 26package org.apache.harmony.jpda.tests.jdwp.MultiSession; 27 28import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 29import org.apache.harmony.jpda.tests.share.SyncDebuggee; 30 31public class EnableCollectionDebuggee extends SyncDebuggee { 32 33 static EnableCollectionObject001_01 checkedObject; 34 static boolean checkedObject_Finalized = false; 35 static EnableCollectionObject001_02 patternObject; 36 static boolean patternObject_Finalized = false; 37 38 @Override 39public void run() { 40 logWriter.println("--> Debuggee: EnableCollectionDebuggee: START"); 41 42 checkedObject = new EnableCollectionObject001_01(); 43 patternObject = new EnableCollectionObject001_02(); 44 45 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 46 String messageFromTest = synchronizer.receiveMessage(); 47 if ( messageFromTest.equals("TO_FINISH")) { 48 logWriter.println("--> Debuggee: EnableCollectionDebuggee: FINISH"); 49 return; 50 } 51 52 logWriter.println("--> Debuggee: BEFORE System.gc():"); 53 logWriter.println("--> Debuggee: checkedObject = " + 54 checkedObject); 55 logWriter.println("--> Debuggee: checkedObject_UNLOADed = " + 56 checkedObject_Finalized); 57 logWriter.println("--> Debuggee: patternObject = " + 58 patternObject); 59 logWriter.println("--> Debuggee: patternObject_UNLOADed = " + 60 patternObject_Finalized); 61 62 checkedObject = null; 63 patternObject = null; 64 long[][] longArray; 65 int i = 0; 66 try { 67 longArray = new long[1000000][]; 68 int arraysNumberLimit = 7; // max - longArray.length 69 logWriter.println 70 ("--> Debuggee: memory depletion - creating 'long[1000000]' arrays (" + arraysNumberLimit + ")..."); 71 for (; i < arraysNumberLimit; i++) { 72 longArray[i] = new long[1000000]; 73 } 74 } catch ( OutOfMemoryError outOfMem ) { 75 logWriter.println("--> Debuggee: OutOfMemoryError!!!"); 76 } 77 longArray = null; 78 System.gc(); 79 logWriter.println("--> Debuggee: AFTER System.gc():"); 80 logWriter.println("--> Debuggee: checkedObject = " + 81 checkedObject); 82 logWriter.println("--> Debuggee: checkedObject_UNLOADed = " + 83 checkedObject_Finalized); 84 logWriter.println("--> Debuggee: patternObject = " + 85 patternObject); 86 logWriter.println("--> Debuggee: patternObject_UNLOADed = " + 87 patternObject_Finalized); 88 89 String messageForTest = null; 90 if ( checkedObject_Finalized ) { 91 if ( patternObject_Finalized ) { 92 messageForTest = "Checked Object is UNLOADed; Pattern Object is UNLOADed;"; 93 } else { 94 messageForTest = "Checked Object is UNLOADed; Pattern Object is NOT UNLOADed;"; 95 } 96 } else { 97 if ( patternObject_Finalized ) { 98 messageForTest = "Checked Object is NOT UNLOADed; Pattern Object is UNLOADed;"; 99 } else { 100 messageForTest = "Checked Object is NOT UNLOADed; Pattern Object is NOT UNLOADed;"; 101 } 102 } 103 logWriter.println("--> Debuggee: Send to test message: \"" + messageForTest + "\""); 104 synchronizer.sendMessage(messageForTest); 105 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 106 107 logWriter.println("--> Debuggee: EnableCollectionDebuggee: FINISH"); 108 109 } 110 111 public static void main(String [] args) { 112 runDebuggee(EnableCollectionDebuggee.class); 113 } 114 115} 116 117class EnableCollectionObject001_01 { 118 @Override 119protected void finalize() throws Throwable { 120 EnableCollectionDebuggee.checkedObject_Finalized = true; 121 super.finalize(); 122 } 123} 124 125class EnableCollectionObject001_02 { 126 @Override 127protected void finalize() throws Throwable { 128 EnableCollectionDebuggee.patternObject_Finalized = true; 129 super.finalize(); 130 } 131} 132