Section 25. (a) Whoever is convicted of a felony and has been previously twice convicted and sentenced to state prison or state correctional facility or a federal corrections facility for a term not less than 3 years by the commonwealth, another state or the United States, and who does not show that the person has been pardoned for either crime on the ground that the person was innocent, shall be considered a habitual criminal and shall be punished by imprisonment in state prison or state correctional facility for such felony for the maximum term provided by law.
(b) Whoever: (i) has been convicted 2 times previously of 1 or more of the following offenses: section 1, section 13, section 131/2, clause (i) of subsection (b) of section 13A, section 13B, subsection (a) of section 13B1/2, section 13B3/4, section 13F, committing an assault and battery upon a child and by such assault and battery causing bodily injury or substantial bodily injury under subsection (b) of section 13J, section 14, section 15, clause (i) of subsection (c) of section 15A, section 16, sections 17 and 18 if armed with a firearm, shotgun, rifle, machine gun, or assault weapon, section 18A, section 18B, section 18C, section 21, section 22, section 22A, section 22B, section 22C, section 23A, section 23B, section 24, section 24B, section 26, section 26B, section 26C, section 28, and subsection (b) of section 39 of chapter 265, section 14 or section 102C of chapter 266, section 4A, section 17, subsection (b) of section 29A, subsection (b) of section 29B, section 29C, section 35A and subsection (b) of section 53A of chapter 272, or has been convicted 2 times previously of a like violation of the laws of another state, the United States or a military, territorial or Indian tribal authority, arising out of charges separately brought and tried, and arising out of separate and distinct incidents that occurred at different times, where the second offense occurred subsequent to the first conviction; (ii) has been sentenced to incarceration at a state prison or state correctional facility or federal correction facility for at least 3 years to be served for each of the prior 2 convictions; and (iii) does not show that he has been pardoned for either prior offense on the ground that he was innocent shall, upon conviction of 1 of the enumerated offenses in clause (i), where the offense occurred subsequent to the second conviction, shall be considered a habitual offender and shall be imprisoned in the state prison or state correctional facility for the maximum term provided by law for the offense enumerated in clause (i). No sentence imposed under this subsection shall be reduced or suspended nor shall such person so sentenced be eligible for probation, parole, work release or furlough or receive any deduction from such person's sentence for good conduct. A sentence imposed on a habitual offender under this subsection, if such habitual offender is incarcerated at a state prison or state correctional facility, shall commence upon the conclusion of the sentence such habitual offender is serving at the time of sentencing.
(c) No person shall be considered a habitual offender under subsection (b) based upon any offense for which such person was adjudicated a youthful offender, a delinquent child, or a like violation of the laws of another state, the United States or a military, territorial or Indian tribal authority for which a person was treated as a juvenile.
(d) Upon sentencing a defendant to a qualifying term of incarceration, or prior to accepting a guilty plea for any qualifying offense listed in subsection (b), the court shall inform the defendant that a conviction or plea of guilty for such an offense implicates the habitual offender statute and that upon conviction or plea of guilty for the third or subsequent of said offenses: (1) the defendant may be imprisoned in the state prison for the maximum term provided by law for such third or subsequent offense; (2) no sentence may be reduced or suspended; and (3) the defendant may be ineligible for probation, parole, work release or furlough, or to receive any deduction in sentence for good conduct. No otherwise valid plea or conviction shall be vacated based upon the failure to give such warnings.