By Agnieszka Barteczko and Pawel Sobczak
WARSAW (Reuters) - Thousands of Poles took to the streets of Warsaw and other Polish cities on Tuesday to protest against the government's makeover of the judiciary that takes effect at midnight despite strong objections by the European Union.
Around 4,000 people -- according to the Warsaw town hall -- gathered outside the Supreme Court in the capital, many shouting "free courts", "shame" and "constitution" and carrying banners and flags of Poland and the EU.
Since the conservative Law and Justice (PiS) party came to power in 2015, Poles have gathered in the streets repeatedly to protest against changes to the judiciary system or plans to make abortion rules more restrictive.
Through legislation and personnel changes, PiS has taken de facto control of the entire judicial system, including the constitutional tribunal and prosecutors, who now report directly to the justice minister.
Its most divisive measure will force more than a third of Supreme Court judges to retire on Wednesday unless they are granted an extension by President Andrzej Duda, a PiS ally.
Duda announced on Tuesday that Supreme Court president Malgorzata Gersdorf, a staunch critic of the reforms, had not asked for an extension and therefore would retire in line with rules introduced by PiS.
"I will still come to work tomorrow, since according to the constitution I have a six-year term to complete," Gersdorf said in parliament after a meeting with Duda.
Earlier on Tuesday she told law students at a lecture that there will be "a purge conducted in the Supreme Court tomorrow under the pretext of the retrospective change in retirement age".
Gersdorf, who had condemned the PiS's alleged campaign to politicise the judiciary and media, had said that under Poland's constitution she should remain in her post until 2020.
More protests are expected on Wednesday. Among those who said they would protest was Lech Walesa, the Nobel Peace Prize Laureate and former president who is credited with bringing down communism as Solidarity trade union chief.
"If in any way the current ruling team attack the Supreme Court, then ... I'm going to Warsaw. It's enough to destroy Poland," Walesa said on his Facebook account.
He also said he was ready to "lead a physical removal of the main perpetrator of all misfortune", referring to PiS leader Jaroslaw Kaczynski.
The European Commission opened a fresh legal case against Poland over the Supreme Court changes on Monday, saying that they undermine judicial independence in the largest formerly communist member of the EU.
The Warsaw government says the reforms are necessary to improve the accountability of a system that dates back to communist times.
The eurosceptic PiS's standing in polls has held steady at around 40 percent throughout the dispute, well above any single rival party.
(Additional reporting by Pawel Florkiewicz, Anna Koper and Anna Wlodarczak-Semczuk; Editing by Mark Heinrich and Phil Berlowitz)